There are two files, a.php and b.php
Click the link in a.php to start downloading the file: The code is as follows
This is a.php.
This is all the code for b.php.
Reply to discussion (solution)
a.php is $file _dir = "D:/files";
Then in the b.php of the $file _dir. $file _name is missing a path character
You have only $file =fopen in b.php ($file _dir $file _name, "R"); Opened the file, but did not output the contents of the file
If using $file =fopen ($file _dir. $file _name, "R"); The open file is a picture, you will not be able to read the picture data correctly
Should be opened in binary mode: $file =fopen ($file _dir. $file _name, "R B");
a.php is $file _dir = "D:/files";
Then in the b.php of the $file _dir. $file _name is missing a path character
You have only $file =fopen in b.php ($file _dir $file _name, "R"); Opened the file, but did not output the contents of the file
If using $file =fopen ($file _dir. $file _name, "R"); The open file is a picture, you will not be able to read the picture data correctly
Should be opened in binary mode: $file =fopen ($file _dir. $file _name, "R B");
Yes, but I changed it to the same thing. The result code is as follows
You can't change the font color in the code, OH, again.
This post was last edited by xuzuning on 2013-06-08 16:08:01
}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); }
Success, the first to thank the moderator, the moderator said very good, and then must share:
is to download compressed files, including files in the compressed file, the code is not difficult
Open File $file = fopen ($file _dir. $file _name, "R");//file type to return header ("Content-type:application/octet-stream");// Returns the header ("Accept-ranges:bytes") by byte size,//Returns the size of the file header ("Accept-length:". FileSize ($file _dir. $file _name));// Here the popup dialog box for the client, corresponding to the filename header ("content-disposition:attachment; Filename= ". $file _dir. $file _name);//Modify the data to the client echo fread ($file, FileSize ($file _dir. $file _name) before modifying, Transmits only 1024 bytes of data at a time to the client//client loopback data $buffer=1024;////determine if the file reads while (!feof ($file)) {//reads the file into memory $file_data=fread ($file, $ buffer);//Echo 1024 bytes of data to the client echo $file _data;} Fclose ($file);