$ _ Files ["file"] ["name"]-name of the uploaded file
$ _ Files ["file"] ["type"]-type of the file to be uploaded
$ _ Files ["file"] ["size"]-size of the uploaded file, in bytes
$ _ Files ["file"] ["tmp_name"]-name of the temporary copy of the file stored on the server
$ _ Files ["file"] ["error"]-error code caused by file upload
<Html>
<Body>
<Form action = "upload_file.php tutorial" method = "post"
Enctype = "multipart/form-data">
<Label for = "file"> filename: </label>
<Input type = "file" name = "file" id = "file"/>
<Br/>
<Input type = "submit" name = "submit" value = "submit"/>
</Form>
</Body>
</Html>
Php code
<? Php
If ($ _ files ["file"] ["type"] = "image/gif ")
| ($ _ Files ["file"] ["type"] = "image/jpeg ")
| ($ _ Files ["file"] ["type"] = "image/pjpeg "))
& ($ _ Files ["file"] ["size"] <20000 ))
{
If ($ _ files ["file"] ["error"]> 0)
{
Echo "error:". $ _ files ["file"] ["error"]. "<br/> ";
}
Else
{
Echo "upload:". $ _ files ["file"] ["name"]. "<br/> ";
Echo "type:". $ _ files ["file"] ["type"]. "<br/> ";
Echo "size:". ($ _ files ["file"] ["size"]/1024). "kb <br/> ";
Echo "stored in:". $ _ files ["file"] ["tmp_name"];
}
}
Else
{
Echo "invalid file ";
}
?>
The $ _ files array contains the following content:
$ _ Files ['myfile'] ['name'] original name of the client file.
$ _ Files ['myfile'] ['type'] indicates the mime type of the file, which must be supported by the browser, for example, "image/gif ".
$ _ Files ['myfile'] ['size'] size of the uploaded file, in bytes.
$ _ Files ['myfile'] ['tmp _ name'] temporary file name stored on the server after the file is uploaded, which is generally the default file name. It can be specified in upload_tmp_dir of php. ini, but the putenv () function setting does not work.
$ _ Files ['myfile'] ['error'] error code related to the file upload. ['Error'] is added in php 4.2.0. The following is its description: (they become constants after php3.0)
Upload_err_ OK
Value: 0. If no error occurs, the file is uploaded successfully.
Upload_err_ini_size
Value: 1; the uploaded file exceeds the limit of the upload_max_filesize option in php. ini.
Upload_err_form_size
Value: 2; the size of the uploaded file exceeds the value specified by the max_file_size option in the html form.
Upload_err_partial
Value: 3; only part of the file is uploaded.
Upload_err_no_file
Value: 4; no file is uploaded.
Value: 5; the size of the uploaded file is 0.