Php bug encountered when downloading images. Today, I encountered a bug when writing a project. when I wrote the image downloading function, I clicked "download", but I couldn't read the image. I also tried a lot of methods, and I felt very depressed. Finally, I encountered a bug when I wrote my classmate's code for the project today. when I wrote the image download function, I clicked download to find that I couldn't read the image. The path was also incorrect in many methods, I feel very depressed. Finally, I got my classmate's code into the exam and still couldn't use it. I was wondering how to use it in his place? Why can't I do this? I was depressed for nearly 30 minutes. Finally, he said that there was no data in front of the header. now I suddenly realized that I should clear the data and suddenly got a sigh of relief, this small problem has delayed nearly one lesson, so I want to share it with you to avoid making such a mistake.
The code is as follows:
/Upload path
[Html]
$ Filename = $ _ GET ["photo"];
// Clear the preceding information
Ob_clean ();
Header ("Content-Type: image/pjpeg ");
Header ("Content-Disposition: attachment; filename =". $ filename );
Header ("Content-Length:". filesize ($ filename ));
Readfile ($ filename );
From xweina's column
Bytes. Finally, let's replace my classmates...