Go to the expert guide and upload the file from the server, but it is empty once it is opened.

Source: Internet
Author: User
Under the guidance of an expert, the files downloaded from the server are empty. Else & quot; open the file; & nbsp; if (! File_exists ($ file_name.
[Code = PHP] [/code]
// Define the image as a variable first;
$ File_name = "QQ20120828234328.png ";
// Open the file;
If (! File_exists ($ file_name )){
Echo "the file does not exist ";
Return;
}
$ Fp = fopen ($ file_name, "r ");
// Obtain the size of the downloaded object
$ File_size = filesize ($ file_name );
// Download the required header file;
// Data download method;
Header ("Content-type: application/octet-stream ");
// Downloads are returned in bytes;
Header ("Accept-ranges: bytes ");
// Size of the downloaded object
Header ("Accept-length: $ file_size ");
// The dialog box popped up by the client, with the corresponding file name.
Header ("Content-Disposition: attachment; filename =". $ file_name );

// Send data back to the client
// Define the text stream
$ Buffer = 1024;
// This statement is used to determine whether the object is ended.
While (! Feof ($ fp )){
// Read text data
$ File_data = fread ($ fp, $ buffer );
// Send some data back to the browser;
}
// Close the file;
Fclose ($ fp );


------ Solution --------------------
// This statement is used to determine whether the object is ended.
While (! Feof ($ fp )){
// Read text data
$ File_data = fread ($ fp, $ buffer );
// Send some data back to the browser;
}
Where are the statements that send some data back to the browser?
------ Solution --------------------
$ File_data = fread ($ fp, $ buffer );
What about echo?

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.