-
- // Check whether the form is completely filled out...
- if ($form_completed) {
- Header("Location: http://www.myweb.com/download/info_check.exe") ;
- exit;
- }
- ?>
- Or:
- Start downloading the file
Copy the code
The ID method is used here to receive the number of the file to be downloaded, and then use " Redirect" method to connect to the actual URL.
For security reasons, users are not allowed to directly copy the URL to download the file. It is recommended to use PHP to directly read the actual file and then download it.
Code:
-
- $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
- // Enter the 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 content
- echo fread($file,filesize($file_dir . $file_name));
- fclose($file);
- exit;}
- ?>
Copy the code
And if the file path is an "http" or "ftp" URL, the source code will change slightly. The procedure is as follows:
-
- $file_name = "info_check.exe";
- $file_dir = "http://www.jincai123.com/";
- $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 Code
Using the above code, you can use php to directly output the file.
|