php实例电影文件验证下载代码
<?php
$dbhost = 'localhost'; // 数据库服务器
$dbuser = 'root'; // 数据库用户名
$dbpw = 'qwaszx'; // 数据库密码
$dbname = 'movie'; // 数据库名
$adminemail = "www.phprm.com@phprm.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." "); //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;
}
}
/***********************************************************/
// ========= 连接数据库 =======================================================
$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;本文地址:http://www.phprm.com/code/33636.html
转载随意,但请附上文章地址:-)