Are you sure you want to laugh at me and say "download files" is that simple? Of course it is not as simple as imagined. For example, if you want the customer to fill out a form before downloading a file, your first thought must be "Redirect, first, check whether the form is complete and complete, and then point the website to this file so that the customer can download it. However, if you want to create an e-commerce website for "online shopping, for security concerns, you do not want users to directly copy the website to download the file. I suggest you use PHP to directly read the actual file and then download it.
Program As follows:
$ File_name = "info_check.exe ";
$ File_dir = "/public/www/download /";
If (! File_exists ($ file_dir. $ file_name) {// check whether the file exists
Echo "file not found ";
Exit;
} Else {
$ File = fopen ($ file_dir. $ file_name, "R"); // open the file
// Input file tag
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 content
Echo fread ($ file, filesize ($ file_dir. $ file_name ));
Fclose ($ file );
Exit ;}
If the file path is "HTTP" or "ftp ",Source codeThere will be a slight change, the program is as follows:
$ File_name = "info_check.exe ";
$ File_dir = "http://www.easycn.net /";
$ 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 );
}
In this way, you can use PHP to directly output files.