Bug_PHP tutorial for downloading images using php

Source: Internet
Author: User
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...

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.