I personally think that the idea of uploading and downloading PHP files is almost the same. Code A header statement is added.
The following code is for reference only.
Portal File
Copy code The Code is as follows: <HTML>
<Body>
<Form action = "Download. php" method = "get"
Enctype = "multipart/form-Data">
<Label for = "file"> filename: </label>
<Input type = "file" name = "FILENAME" id = "fileid" value = "<? PHP echo $ _ FILES ["file"] ["name"];?> "/>
<H1> <Input type = "Submit" name = "Submit" value = "Download"/>
</Form>
</Body>
</Html>
Processing files written in PHP
<? PHP
If (empty ($ _ Get ['filename']) {
Echo '<SCRIPT> alert ("illegal connection! "); Location. Replace ("./fileload.html ") </SCRIPT> '; exit ();
}
$ File_name = $ _ Get ['filename']; // get the object to be downloaded
If (! File_exists ($ file_name) {// check whether the file exists
Echo "file not found ";
Exit;
} Else {
$ File = fopen ($ file_name, "R"); // open the file
// Input file tag
Header ("Content-Type: Application/octet-stream ");
// Header ("Accept-ranges: bytes ");
// Header ("Accept-length:". filesize ($ file_name ));
// Header ("content-Disposition: attachment; filename =". $ file_name );
// Output file content
Echo fread ($ file, filesize ($ file_name ));
Fclose ($ file );
Exit ();
}
?>
The above code is found on the Internet, but it is not complete. I have recorded debugging and modification for a while. finally, the function is implemented. I am so excited that I will share it with you in the first time.