php實例電影檔案驗證下載代碼

來源:互聯網
上載者:User
關鍵字 網路程式設計 PHP教程

<?php教程


$dbhost = 'localhost';    資料庫教程伺服器
$dbuser = 'root';     資料庫使用者名
$dbpw = 'qwaszx';             資料庫密碼
$dbname = 'movie';  資料庫名
$adminemail = www.jzread.com@jzread.com; 系統管理員 email


$database = 'mysql教程';  不能修改此處
$tplrefresh = 1;  範本自動刷新開關 0=關閉, 1=打開
$pconnect = 0;   資料庫連接方式 0=connect, 1=pconnect

// ============================================================================

class db_class {
var $querynum = 0;
function dbstuff() { global $fp; $fp = fopen("./tempdata/dblog.txt", "w"); }

function connect($dbhost, $dbuser, $dbpw, $dbname, $pconnect = 0) {
if($pconnect) {
if(!@mysql_pconnect($dbhost, $dbuser, $dbpw)) {
$this->halt('can not connect to mysql server');
}
} else {
if(!@mysql_connect($dbhost, $dbuser, $dbpw)) {
$this->halt('can not connect to mysql server');
}
}
mysql_query("set names 'gb2312'");
}

function select_db($dbname) {
return mysql_select_db($dbname);
}

function fetch_array($query, $result_type = mysql_assoc){


$query = mysql_fetch_array($query, $result_type);

return $query;
}

 function query($sql, $silence = 0) {
  //echo "|$sql|<br>"; //debug
  //@fwrite($globals [fp], $sql." n"); debug
  $query = mysql_query($sql);
        //echo 'query:'.$query.' <br>';
     if(!$query && !$silence)
        {
& nbsp;        $this->halt('mysql query error', $sql);
  }
        $this->querynum++;
  return $query;
 }


 function unbuffered_query($sql, $silence = 0) {
  $func_unbuffered_query = @function_exists(' mysql_unbuffered_query') ? 'mysql_unbuffered_query' : 'mysql_query';
  $query = $func_unbuffered_query($sql);
  if(!$query && !$silence) {
   $this->halt('mysql query error', $sql);
  }
  $this->querynum++;
  return $query;
 }
 function get_one($sql){
        $sql=$sql;
  if(function_ exists('mysql_unbuffered_query')){
   $query = mysql_unbuffered_query($sql);
  }else{
   $query = mysql_query($sql);
  }
  $this->querynum++;
  if (!$query)  $this->halt('query error: ' . $sql);
 
  $rs =& mysql_fetch_array($query, mysql_assoc);
  mysql_free_result($query);
& nbsp; return $rs;
 }

function affected_rows() {
return mysql_affected_rows();
}

function error() {
return mysql_error();
}

function errno() {
return mysql_errno();
}

function result($query, $row) {
$query = @mysql_result($query, $row);
return $query;
}

function num_rows($query) {
$query = mysql_num_rows($query);
return $query;
}

function num_fields($query) {
return mysql_num_fields($query);
}

function free_result($query) {
return mysql_free_result($query);
}

function insert_id() {
$id = mysql_insert_id();
return $id;
}

function fetch_row($query) {
$query = mysql_fetch_row($query);
return $query;
}

function close() {
return mysql_close();
}
function halt($message = '', $sql = '') {
echo $message;
}

}


***********************************************************/
========= 連接資料庫 =======================================================
$db = new db_class;
$db->connect($dbhost, $dbuser, $dbpw, $pconnect);
$db->select_db($dbname);
unset($dbhost, $dbuser, $dbpw, $dbname, $pconnect);

實例資料下載

<?
include './admin/connect.php';

@extract($db->get_one("select * from movieinfo where id='".$_get['id']."'"));
$db->query("update movieinfo set downnum=downnum+1 where id='".$_get['id']."'");
控制下載
$url2="./admin/";//存放電影的路徑


if($localaddress)
{
$newname=$localaddress;
$movieurl=$url2.$newname;
}


$type=basename($movieurl);
$type= substr(strrchr($type,'.'),0);
$filename=$title.$type;

$file=fopen($movieurl,'r');
ob_end_clean();
header('content-type: application/octet-stream');
header('accept-ranges: bytes');
header('accept-length:'.filesize($movieurl));
header("content-disposition: attachment; filename=".$filename);
echo fread($file,filesize($movieurl));
fclose($file);
exit;
?>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.