Php beginners-about file downloading Hello everyone. I am a beginner. I just watched the file downloading section in the video of Chuanzhi podcast, according to the code given by instructor Han, why is the picture displayed on the page rather than downloaded from the browser? Thank you for your help & lt ;? Php?file_name"=mao.jpg & quot; if (! File_exists ($ file php for beginners-about file download
Hello everyone, I am a newbie. I just read the file download section in the video of Chuanzhi podcast. I wrote it myself according to the code given by instructor Han, but why is the image displayed on the page instead of being downloaded from the browser?
Thank you for your help.
$ File_name = "mao.jpg ";
If (! File_exists ($ file_name )){
Echo "the file does not exist! ";
Return;
}
$ Fp = fopen ($ file_name, "r ");
$ File_size = filesize ($ file_name );
Header ("Content-type: application/octet-stream ");
Header ("Accept-Ranges: bytes ");
Header ("Accept-Length: $ file_size ");
Header ("Content-Disponsition: attachment; filename =". $ file_name );
$ Buffer = 1024;
While (! Feof ($ fp )){
$ File_data = fread ($ fp, $ buffer );
Echo $ file_data;
}
Fclose ($ fp );
?>
------ Solution --------------------
Header ("Content-Disponsition: attachment; filename =". $ file_name); n is added here, so it is invalid.