Php image Upload implementation code. First, understand the content of the $ _ files array of the files function: $ _ files [myfile] [name] The original name of the client file. $ _ Files [myfile] [type] the mime type of the file. you need to provide this information in the browser to understand the files function first.
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. You can specify upload_tmp_dir in the php Tutorial. 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.
Php code
$ Mkdir_file_dir = mkdir ('./img/'. $ _ post ['title'], 0777); // create an image-related directory when uploading a file
$ Tmp_file_name = $ _ files ['file'] ['tmp _ name']; // temporary file name obtained after successful Upload
$ File_name = $ _ files ['file'] ['name']; // original file name
$ File_dir = './img/'. $ _ post ['title']. '/'; // assign the created directory to a variable as the final storage directory.
If (is_dir ($ file_dir ))
{
Move_uploaded_file ($ tmp_file_name, $ file_dir. $ file_name); // start to move the file
}
?>
Html code
<Br/> my is upfile app !! <Br/>
After a file is submitted through post, it is saved in the c: windowstemp temporary folder through $ _ files ["photo"] ["tmp_name"], we can easily obtain the uploaded temporary file and save it to the path we specified. below is the solution move_uploaded_file ($ _ files ["photo"] ["tmp_name"], $ path)
The program $ _ files array contains the following content: $ _ files ['myfile'] ['name'] The original name of the client file. $ _ Files ['myfile'] ['type'] indicates the mime type of the file, which must be provided by the browser...