Personally, I think the idea of uploading and downloading PHP files is almost the same. That is, there is an extra header statement in the code. The following is the detailed code. For reference only.
Entry file
Copy the code The code is as follows:
php Write processing files
if( empty($_GET['FileName'])){
echo'<script> alert("Illegal connection!"); location.replace ("./fileload.html ") </script>'; exit();
}
$file_name=$_GET['FileName'];//Get the file 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
// Enter the 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();
}
?>
I found the above codes on the Internet, but they were not complete. After a period of debugging and modification, I finally realized the function. I was so excited that I shared it with everyone as soon as possible.
The above introduces the implementation code of uploading PHP file upload function, including uploading content. I hope it will be helpful to friends who are interested in PHP tutorials.