function Down_file ($file _name, $file _path) {
@ $file _name=iconv ("Utf_8", "gb2312", $file _name);
$file _path=$_server[' Document_root '). $file _path. $file _name;
if (!file_exists ($file _path)) {
echo "file does not exist";
Return
}
$FP =fopen ($file _path, "r+");
$file _size=filesize ($file _path);
Header ("Content-type:application/octet-stream");
Header ("Accept-rangers:bytes");
Header ("Accept-length: $file _size");
Header ("Content-dispostion:attachment;filename=". $file _name);
while (!feof ($file _path)) {
$data =fread ($FP, 1024);
Echo $data;
}
Fclose ($FP);
}
Down_file ("Php.png", "/down/");
?>
Reply to discussion (solution)
Add a download type to try the header ("Content-type:image/png");
Same #
Header ("Content-dispostion:attachment;filename=". $file _name);
This is a path, isn't it?
Header ("Content-dispostion:attachment;filename=". BaseName ($file _name));
That's it.
Thank you, three people, you're right.
1? and 2?? Bit ...
Add header ("Content-type:image/png");? useful, because it is the next, not the.
First of all, you don't have code at all. Yes,???? The
@ $file _name=iconv ("Utf_8", "gb2312", $file _name);?? It's UTF-8.
while (!feof ($file _path)) {?? It's $fp.
Header ("Content-dispostion:attachment;filename=". $file _name);?? It's disposition.
Change to?? You can do it.
function Down_file ($file _name, $file _path) {@ $file _name=iconv ("Utf-8", "gb2312", $file _name); $file _path=$_server[' Document_root ']. $file _path. $file _name;if (!file_exists ($file _path)) {echo "file does not exist"; return;} $FP =fopen ($file _path, "r+"), $file _size=filesize ($file _path); Header ("Content-type:application/octet-stream"); Header ("Accept-rangers:bytes"), Header ("Accept-length: $file _size"), Header ("content-disposition:attachment; Filename= ". $file _name), while (!feof ($fp)) {$data =fread ($fp, 1024x768); echo $data;} Fclose ($FP);} Down_file ("Php.png", "/down/");