Understand the files function first
The contents of the $_files array are as follows:
$_files[' myfile ' [' Name '] The original name of the client file.
The MIME type of the $_files[' myfile ' [' type '] file requires the browser to provide support for that information, such as "Image/gif".
$_files[' myfile ' [' size '] the size of the uploaded file, in bytes.
$_files[' myfile ' [' tmp_name '] files are uploaded after the temporary file name stored on the server, usually the system default. You can specify Upload_tmp_dir in the PHP tutorial. ini, but using the putenv () function setting is not working.
$_files[' myfile ' [' Error '] and the file upload related error code. [' ERROR '] was added in version php 4.2.0. Here is a description of it: (they become constants after php3.0)
Upload_err_ok
Value: 0; No error occurred and the file upload was successful.
Upload_err_ini_size
Value: 1; The uploaded file exceeds the value of the Upload_max_filesize option limit 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 files were uploaded.
Value: 5; The upload file size is 0.
PHP code
$mkdir _file_dir = mkdir ('./img/'. $_post[' title '],0777); When uploading a file, start creating an image-related directory
$tmp _file_name = $_files[' file ' [' Tmp_name ']; Temporary file name to be taken after successful upload
$file _name = $_files[' file ' [' Name ']; The original file name
$file _dir = './img/'. $_post[' title ']. ' /'; Assign the created directory to a variable as the final save directory
if (Is_dir ($file _dir))
{
Move_uploaded_file ($tmp _file_name, $file _dir. $file _name); Start moving files
}
?>
HTML code
<br/> My is upfile app!! <br/>
It is very important to note that the file is saved in the C:windowstemp Temp folder after post submission by $_files["Photo" ["Tmp_name"], we can easily get the uploaded temporary file, save it to our designated path Here is the solution move_uploaded_file ($_files["Photo" ["Tmp_name"], $path)
http://www.bkjia.com/PHPjc/632988.html www.bkjia.com true http://www.bkjia.com/PHPjc/632988.html techarticle first understand the files function $_files array contents as follows: $_files[' myfile ' [' Name '] The original name of the client file. The MIME type of $_files[' myfile ' [' type '] file requires the browser to provide the letter ...