? <PHP
header ( "Content-of the type: text / HTML; charset = UTF-8");
$ file_name = "1.text";
// solve Chinese problems can not be displayed
$ file_name = iconv ( "utf- 8" , "GB2312", $ file_name);
$ path1 = $ _ SERVER [ 'DOCUMENT_ROOT'];
. $ filepath = $ path1 $ file_name;
whether // Analyzing file exists
(! the file_exists ($ file_path) iF) {
echo "the file is not file ";
return;
}
$ fp = fopen ($ filepath," r ");
$ FILE_SIZE = filesize ($ filepath);
// download file need to use the head
header (" Content-type: application / octet-stream " );
Header ( "the Accept-Ranges: bytes");
Header ( "the Accept-the Length:" $ FILE_SIZE);.
Header ( "the Content-Disposition: Attachment; filename =" $ file_name);.
Buffer = 1024 $;
$ FILE_COUNT = 0;
// returns the data to the browser
while(!feof($fp) && $file_count<$file_size){
$file_con=fread($fp,$buffer);
$file_count+=$buffer;
echo $file_con;
}
fclose($fp);
?>
php achieve download
Guess you like
Origin www.cnblogs.com/xhen/p/11077912.html
Ranking