Php file upload and download source code ,. Php file upload and download source code. 1. file Upload foreground page :! DOCTYPEhtmlhtmlheadmetacharsetutf-8title file Upload titleheadbodydivforw.hodposta php file upload and download source code,
I. file Upload
Front-end page:
File Upload
User name
File introduction
Select the file to Upload
Background processing:
"; // Print_r ($ _ FILES); // echo"
"; // You can limit the file size here/* $ filesize = $ _ FILES ['myfile'] ['size']; if ($ filesize> 2*1024*1024) {echo "the file is too large to upload"; exit ();} * /// You can restrict the file type./* $ filetype = $ _ FILES ['myfile'] ['type']; if ($ filetype! = 'Image/jpg '& $ filetype! = 'Application/pdf ') {echo "file types can only be jpg and pdf"; exit ();} */if (is_uploaded_file ($ _ FILES ['myfile'] ['tmp _ name']) {// Save the file to the directory you want to store $ uploaded = $ _ FILES ['myfile'] ['tmp _ name']; // each user dynamically creates a folder $ userpath =$ _ SERVER ['document _ root']. "/up /". $ name; // Determine whether the user already has a folder if (! File_exists ($ userpath) {mkdir ($ userpath);} // prevents the same user from uploading files of the same name. you can add a timestamp to the file. // $ Moveto = $ userpath. "/". time (). $ _ FILES ['myfile'] ['name']; // or modify the file name, however, the file suffix $ truename = $ _ FILES ['myfile'] ['name']; $ moveto = $ userpath must be used for string processing. "/". time (). substr ($ truename, strrpos ($ truename ,". "); if (move_uploaded_file ($ uploaded, iconv (" UTF-8 "," gb2312 ", $ moveto) {echo" Upload file ". $ _ FILES ['myfile'] ['name']. "succeeded";} else {echo "uploading files ". $ _ FILES ['myfile'] ['name']. "failed" ;}} else {echo "Upload file ". $ FILES ['myfi Le '] ['name']. "failed" ;}?>
II. file download:
Single file download:
0) {$ file_data = fread ($ fp, $ buffer); // count the number of bytes read $ file_count + $ buffer; echo $ file_data; // send some data to the browser} fclose ($ fp); // close the file}?>
Download multiple files:
DownList. php:
down
down
down
down
Downprocess. php:
0) {$ file_data = fread ($ fp, $ buffer); // count the number of bytes read $ file_count + $ buffer; echo $ file_data; // send part of the data to the browser} fclose ($ fp);} down_file ($ filename);?>
Upload, I. file upload front-end page :! DOCTYPE html head meta charset = "UTF-8" title file upload/title/head body p form method = "post"...