Exercise php file upload, the uploaded image cannot be opened
Source: Internet
Author: User
Exercise php file download, the downloaded image cannot be opened & lt ;? Php?file_name="=hello.jpg & quot; if (! File_exists ($ file_name) {echo & quot; the file does not exist & quot; return;} $ fp = fopen ($ file_name, & exercise php file download. the downloaded image cannot be opened
$ File_name = "hello.jpg ";
If (! File_exists ($ file_name ))
{
Echo "the file does not exist ";
Return;
}
$ Fp = fopen ($ file_name, "r ");
// Get the downloaded file size
$ File_size = filesize ($ file_name );
Echo $ file_size;
// Returned file
Header ("Content-type: application/octet-stream ");
// Returns the value in bytes.
Header ("Accept-Ranges: byte ");
// Returns the file size.
Header ("Accept-Length: $ file_size ");
// The pop-up dialog box on the client, with the corresponding file name
Header ("Content-Disposition: attachment; filename =". $ file_name );
$ Buffer = 1024;
// Determine whether the end of the file ends.
While (! Feof ($ fp ))
{
// Echo "1111 ";
$ File_data = fread ($ fp, $ buffer );
// Send some data back to the browser
Echo $ file_data;
}
Fclose ($ fp );
?>
The prompt that the image file cannot be opened is: the file may be damaged or too large.
------ Solution --------------------
Echo $ file_size; // comment out this sentence
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.