- // Check whether all FORM fields are complete...
- If ($ form_completed ){
- Header ("Location: http://bbs.it-home.org/download/info_check.exe ");
- Exit;
- }
- ?>
Or the following: start to download the file. here, the ID method is used to receive the number of the file to be downloaded, and then the "Redirect" method is used to connect to the actual website. If you do not want to directly copy the URL to download the file, you can use PHP to directly read the actual file and then download it. The code is 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 an "http" or "ftp" URL, the source code will change a little. 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 );
- }
- ?>
-
In this way, you can use PHP to directly output files. The above uses the php header function. For more information, see the php file header (header. Php file secure download code
// Secure File 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 );
- }
- }
- ?>
|