//I encountered a bug when I was writing a project today. When I was writing the function of downloading pictures, I couldn’t read the picture when I clicked the download button. The path was correct and I tried many methods but nothing was right. I felt very depressed. In the end, my classmate's code passed the test but it still didn't work. I was wondering how it could be used in his place? Why can't I do this? I was depressed for nearly 30 minutes. Finally, he said that there can't be data in front of the header. At this time, it suddenly dawned on me that yes, it should be cleared. I let out a sigh of relief. Such a small problem delayed nearly a class. , so I want to share it with everyone so that you don’t make such mistakes again
The code is as follows:
/upload path
[html]
$filename=$_GET["photo"];
//Clear the above information
ob_clean();
header("Content-Type:image/pjpeg");
header("Content-Disposition:attachment;filename=".$filename);
header("Content-Length:".filesize($filename));
readfile($filename);