Php Cainiao solution-about file download

Source: Internet
Author: User
Tags php for beginners
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&quot=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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.