1, php download schematic diagram
2, File download Source:
Copy Code code as follows:
<?php
$file _name= "haha. jpg";//Files to download
$file _name=iconv ("Utf-8", "gb2312", "$file _name");
$FP =fopen ($file _name, "r+");//download file must first open file, write to memory
if (!file_exists ($file _name)) {//Determine if the file exists
echo "file does not exist";
Exit ();
}
$file _size=filesize ("a.jpg");//Determine File size
The file returned
Header ("Content-type:application/octet-stream");
return in byte format
Header ("Accept-ranges:bytes");
Return file size
Header ("Accept-length:". $file _size);
Pop-up Client dialog box, corresponding filename
Header ("content-disposition:attachment; Filename= ". $file _name);
To prevent the server from increasing instantaneous pressure, segmented read
$buffer = 1024;
while (!feof ($fp)) {
$file _data=fread ($fp, $buffer);
echo $file _data;
}
Close File
Fclose ($FP);
?>
3, File coding problem Solving method:
If the file name is Chinese, PHP functions can not recognize the Chinese file name, generally if the program code for the utf-8,php function is relatively old, can only identify gb2312 encoded in Chinese, so the Chinese with Iconv ("Original Code", "to convert to the code", "to transcoding the string") function to transcoding.
For example, turn a string from Utf-8 to gb2312
$file _name=iconv ("Utf-8", "gb2312", "$file _name");