PHP file upload code

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.