PHP instance movie file verification download code

Source: Internet
Author: User
Keywords Web Programming PHP Tutorials
Tags code connect download echo error file file verification function

<?php Tutorial


$dbhost = ' localhost '; Database Tutorial Server
$dbuser = ' root '; Database username
$DBPW = ' QWASZX '; Database Password
$dbname = ' movie '; Database name
$adminemail = www.jzread.com@jzread.com; System Administrator Email


$database = ' MySQL tutorial '; Cannot modify here
$tplrefresh = 1; Template Auto Refresh Switch 0 = close, 1 = Open
$pconnect = 0; Database connection mode 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)
        {
         $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);
  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;
}

}


***********************************************************/
========= Connection Database =======================================================
$db = new Db_class;
$db->connect ($dbhost, $dbuser, $DBPW, $pconnect);
$db->select_db ($dbname);
Unset ($dbhost, $dbuser, $DBPW, $dbname, $pconnect);

Instance Data downloads

?
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 '). "
Control Downloads
$url 2= "./admin/"/The path to the movie


if ($localaddress)
{
$newname = $localaddress;
$movieurl = $url 2 $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;
?>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.