If you are a computer enthusiast and do not know PHP, you will be too outdated. If you want to know about PHP, let's take a look at the implementation of PHP file upload. This code is divided into two files, one is upload.html and the other is upload. php.
- <Form Enctype="Multipart/form-data" Action="Upload. php" Method="Post">
- <Input Type="Hidden" Name="Max_file_size" Value="100000">
- <Input Name="Userfile" Type="File">
- <Input Type="Submit" Value="Upload files">
- </Form>
Note that <form enctype = "multipart/form-data" ......> this is a tag. to upload a file, you must specify it as multipart/form-data. Otherwise, the server will not know what to do. The Value is the hidden Value range of the form option MAX_FILE_SIZE in the file upload.html. You can set the Value to limit the size of the uploaded file. The value of MAX_FILE_SIZE is only a suggestion for the browser. In fact, it can be simply bypassed. Therefore, do not forward browser restrictions to this value. In fact, PHP sets the maximum number of PHP files to be uploaded. But it is best to add MAX_FILE_SIZE to the form, because it can avoid the trouble of finding the file too big after you wait for the upload of a large file.
- Upload. php
- $F= & $ HTTP_POST_FILES ['myfile'];
- $Dest_dir='Uploads'; // Set the upload directory
- $Dest= $ Dest_dir. '/'. date ("ymd"). "_". $ f ['name']; // set the file name to date and add the file name to avoid duplication.
- $R=Move_uploaded_file($ F ['tmp _ name'], $ dest );
- Chmod ($ dest, 0755); // sets the attributes of the uploaded file
Or
- <?copy($_FILES[MyFile][tmp_name],$_FILES[MyFile][name]);?>
In the preceding example, the content of the $ _ FILES array is as follows. Assume that the name of the file upload field is userfile)
- $ _ FILES ['userfile'] ['name'] // the original name of the client machine file.
- $ _ FILES ['userfile'] ['type'] // MIME type of the file, which must be supported by the browser, for example, "image/gif ".
- $ _ FILES ['userfile'] ['SIZE'] // size of the uploaded file, in bytes.
- $ _ FILES ['userfile'] ['tmp _ name'] // temporary file name stored on the server after the file is uploaded.
- $ _ FILES ['userfile'] ['error'] // error Code related to the File Upload
PHP File Upload value analysis:
◆ Value: 0. If no error occurs, the file is uploaded successfully.
◆ Value: 1; the uploaded file exceeds the limit of the upload_max_filesize option in php. ini.
◆ Value: 2; the size of the uploaded file exceeds the value specified by the MAX_FILE_SIZE option in the HTML form.
◆ Value: 3; only part of the file is uploaded.
◆ Value: 4; no file is uploaded.