Home > Backend Development > PHP Tutorial > Upload PHP file upload function implementation code

Upload PHP file upload function implementation code

WBOY
Release: 2016-07-29 08:40:11
Original
717 people have browsed it

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:



enctype="multipart/form-data">

" />
< ;h1>




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.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template