Php download problem. after the download, the file content is blank, and the image is not previewed. There are two files, a. php and B. php.
Click the link in a. php to download the file: the code is as follows:
This is a. php
This is all B. php code.
Reply to discussion (solution)
In a. php, $ file_dir = "D:/files ";
In B. php, $ file_dir. $ file_name lacks the path character.
In B. php, you only have $ file = fopen ($ file_dir. $ file_name, "r"); opened the file, but no output file content.
If $ file = fopen ($ file_dir. $ file_name, "r") is used; if the opened file is an image, the image data cannot be read correctly.
Open in binary mode: $ file = fopen ($ file_dir. $ file_name, "r B ");
In a. php, $ file_dir = "D:/files ";
In B. php, $ file_dir. $ file_name lacks the path character.
In B. php, you only have $ file = fopen ($ file_dir. $ file_name, "r"); opened the file, but no output file content.
If $ file = fopen ($ file_dir. $ file_name, "r") is used; if the opened file is an image, the image data cannot be read correctly.
Open in binary mode: $ file = fopen ($ file_dir. $ file_name, "r B ");
I understand it, but I changed it to this. The result code is as follows:
The font color cannot be changed in the dizzy code.
This post was last edited by xuzuning at 16:08:01 on
}else{ $file = $file_dir.$file_name; Header("Content-type: application/octet-stream"); Header("Accept-Ranges:bytes"); Header("Accept-Length:".filesize($file)); Header("Content-Disposition: attachment; filename=".$file_name); readfile($file); }
Thanks to the moderator. the moderator speaks very well and must share the following information:
It is used to download compressed files, including the files in the compressed files, and the code is not difficult
// Open the file $ file = fopen ($ file_dir. $ file_name, "r"); // The Returned file type Header ("Content-type: application/octet-stream "); // return the Header ("Accept-Ranges: bytes") according to the byte size; // return the file size Header ("Accept-Length :". filesize ($ file_dir. $ file_name); // The pop-up dialog box for the client, the corresponding file name Header ("Content-Disposition: attachment; filename = ". $ file_dir. $ file_name); // transmit data to the client echo fread ($ file, filesize ($ file_dir. $ file_name); // after modification, only 1024 bytes of data are transmitted at a time to the client. // Send data back to the client $ buffer = 1024; // Determine whether the file has been read while (! Feof ($ file) {// read the file into the Memory $ file_data = fread ($ file, $ buffer ); // send 1024 bytes of data back to the client each time echo $ file_data;} fclose ($ file );