Copy CodeThe code is as follows:
Public Function Downloads ($name) {
$name _tmp = Explode ("_", $name);
$type = $name _tmp[0];
$file _time = Explode (".", $name _tmp[3]);
$file _time = $file _time[0];
$file _date = Date ("Y/md", $file _time);
$file _dir = Site_path. " /data/uploads/$type/$file _date/";
if (!file_exists ($file _dir. $name)) {
Header ("content-type:text/html; Charset=utf-8 ");
echo "File not found!";
Exit
} else {
$file = fopen ($file _dir. $name, "R");
Header ("Content-type:application/octet-stream");
Header ("Accept-ranges:bytes");
Header ("Accept-length:". FileSize ($file _dir. $name));
Header ("content-disposition:attachment; Filename= ". $name);
Echo fread ($file, FileSize ($file _dir. $name));
Fclose ($file);
}
}
Example 2: Code implementation file Download
The general implementation of the download is the call URL to download, but encountered IE can recognize open files can not be used in this way, such as downloading a picture, HTML page, etc., then need to be programmed to implement, the following PHP code can be resolved:
Copy the Code code as follows:
if (Empty ($_get[' FileName ']) | | empty ($_get[' Filedir ')) | | empty ($_get[' FileId '])) {
Echo '; Exit ();
}
$file _name=$_get[' FileName ';
$file _dir=$_get[' Filedir '];
$FileId =$_get[' FileId '];
$file _dir = $file _dir. " /";
if (!file_exists ($file _dir. $file _name)) {//check if file exists
echo "File not found";
Exit
} else {
$file = fopen ($file _dir. $file _name, "R"); Open File
Input File Label
Header ("Content-type:application/octet-stream");
Header ("Accept-ranges:bytes");
Header ("Accept-length:". FileSize ($file _dir. $file _name));
Header ("content-disposition:attachment; Filename= ". $file _name);
Output file contents
Echo fread ($file, FileSize ($file _dir. $file _name));
Fclose ($file);
Exit ();
}
?>
http://www.bkjia.com/PHPjc/739781.html www.bkjia.com true http://www.bkjia.com/PHPjc/739781.html techarticle Copy the code code as follows: Public function downloads ($name) {$name _tmp = explode ("_", $name); $type = $name _tmp[0]; $file _time = Explod E (".", $name _tmp[3]); $file _time = $file _time[0 ...