td>
TR>
Form> center> table> body>
Html> [Ctrl A All Choose to copy]
It is worth noting that a hidden value domain of a max_file_size, which can limit the size of the upload file by setting its value. Then implement file upload operation in the background. If it is just the most basic upload, you can get it.
If ($ uploadfile! = "None") {copy ($ uploadfile, "$ uploadfile_name); unlink ($ uploadfile);} else {echo" You did not select any file upload! ";}?>
Because the value of Form is automatically assigned to the same name variable, the uploaded file can be accessed directly through the $ uploadfile, but because this is a saved file variable, the file name must be obtained by another $ uploadFile_name variable. Delete the temporary file (UNLINK) after copying the file.
The above code is fully working, but the actual application is loophole, let us gradually improve the first, and the uploaded file must have a fixed directory save, we are saved here, such as $ uploadPath = "/ Home / Flier / Upload / ";
Or complicated automatic positioning, such as
$ UPLOADPATH = addslashes ($ PATH_TRANSLATED)). "// Upload //"; $ PATH_TRANSLATED Assending Six is the current transfer directory
We assume that the uploaded file is saved with a subdirectory named UPLOAD. The dirName function returns its directory name, then add the subdirectory name and save the full upload file name and path with a variable $ filename.
$ Filename = $ uploadpath. $ Uploadfile_name;
Second, we also want users to know the brief information of uploading files, such as the size IF of uploading files ($ UPLOADFILE_SIZE <1024) {// Upload file size $ filesize = (string) $ uploadfile_size. "Byte";} elseif $ UPLOADFILE_SIZE <(1024 * 1024)) {$ filesize = Number_Format ($ UPLOADFILE_SIZE / 1024), 1). "Kb";} else {$ filesis = number_format ($ uploadfile_size / (1024 * 1024)), 1). "MB";} Number_format function plays a role in formatting the output, please refer to the manual for specific usage. Next We must consider the case where the file already exists and the copy operation failed, and provides the corresponding prompt information if (! File_exists ($ filename)) {if ($ uploadfile, $ filename)) {echo file $ uploadfile_name $ Filesize) Upload success! ";} Else {echo" file $ uploadfile_name upload failed! ";} Unlink ($ uploadfile);} else {echo" file $ uploadFile_name already exists! ";} Then we should consider the big file upload When the timeout is prone to, you can use set_time_limit ($ TIMELIMIT); increase the timeout limit time.
Finally, integrate the cross section and implementation code into a separate file. In order to achieve this idea, we add a hidden value to the Form
Upload.php3:
IF ($ uploadAction):
?>
File Upload Interface Title>
HEAD>
|