The code is as follows:
<?php header ("Content-type=html/text;charset=utf-8"); function Download ($file _name, $file _sub_dir) {$file _name = iconv ("Utf-8", "gb2312", $file _name); $file _path = $_server[' Document_root ']. $file _sub_dir. $file _name;if (!file_exists ($file _path)) {echo "file does not exist"; return;} $fp = fopen ($file _path, "RB"), $file _size = filesize ($file _path); Header ("Content-type:application/octet-stream"); Header ("Accept-ranges:bytes"), Header ("Accept-length: $file _size"), Header ("content-disposition:attachment; Filename= ". $file _name); $buffer = 1024x768; $file _count = 0;while (!feof ($fp) && $file _size-$file _count>0) {$file _data = Fread ($fp, $buffer) $file _count+= $buffer; echo $file _data;} Fclose ($FP);} Download ("Picture1.jpg", "/txt/");?>
The downloaded picture is successful, but when the picture is opened, the display picture is corrupted;
I spent one hours debugging, and finally found the problem: The reason for the file encoding;
The new file must be Utf-8 (Special note: Save with Notepad as Utf-8, you must create a new Utf-8 file), and use an editor such as Notepad++,sublime.
PHP Remote Download picture corruption problem