- Check if the form is complete ...
- if ($form _completed) {
- Header ("Location:http://bbs.it-home.org/download/info_check.exe");
- Exit
- }
- ?>
Copy CodeOr the following: To start the download file here, the ID is used to receive the number of the file to download, and then "Redirect" the way to connect to the actual URL. If you do not want users to directly copy the URL to download the file, you can consider using PHP directly read the actual file and then download the method to implement. The code is as follows:
- $file _name = "Info_check.exe";
- $file _dir = "/public/www/download/";
- if (!file_exists ($file _dir. $file _name)) {//check if file exists
- echo "File not found";
- Exit
- } else {
- $file = fopen ($file _dir. $file _name, "R"); Open File
- Input File Label
- Header ("Content-type:application/octet-stream");
- Header ("Accept-ranges:bytes");
- Header ("Accept-length:". FileSize ($file _dir. $file _name));
- Header ("content-disposition:attachment; Filename= ". $file _name);
- Output file contents
- Echo fread ($file, FileSize ($file _dir. $file _name));
- Fclose ($file);
- Exit;}
- ?>
Copy CodeIf the file path is "http" or "FTP" URL, then the source code will be slightly changed, the code is as follows:
- $file _name = "Info_check.exe";
- $file _dir = "http://bbs.it-home.org/";
- $file = @ fopen ($file _dir. $file _name, "R");
- if (! $file) {
- echo "File not found";
- } else {
- Header ("Content-type:application/octet-stream");
- Header ("content-disposition:attachment; Filename= ". $file _name);
- while (!feof ($file)) {
- Echo fread ($file, 50000);
- }
- Fclose ($file);
- }
- ?>
Copy CodeThis allows you to output the file directly with PHP. The above uses the PHP header function, more content can be consulted: PHP file header information detailed. Code to implement safe download of PHP files
File Security Download
- Public Function Downloads ($name) {
- $name _tmp = Explode ("_", $name);
- $type = $name _tmp[0];
- $file _time = Explode (".", $name _tmp[3]);
- $file _time = $file _time[0];
- $file _date = Date ("Y/md", $file _time);
- $file _dir = Site_path. " /data/uploads/$type/$file _date/";
if (!file_exists ($file _dir. $name)) {
- Header ("content-type:text/html; Charset=utf-8 ");
- echo "File not found!";
- Exit
- } else {
- $file = fopen ($file _dir. $name, "R");
- Header ("Content-type:application/octet-stream");
- Header ("Accept-ranges:bytes");
- Header ("Accept-length:". FileSize ($file _dir. $name));
- Header ("content-disposition:attachment; Filename= ". $name);
- Echo fread ($file, FileSize ($file _dir. $name));
- Fclose ($file);
- }
- }
- ?>
Copy Code |