Home > Backend Development > PHP Tutorial > Important functions in $_FILES file upload in php_PHP tutorial

Important functions in $_FILES file upload in php_PHP tutorial

WBOY
Release: 2016-07-20 11:02:18
Original
931 people have browsed it

$_files["file"]["name"] - the name of the uploaded file
$_files["file"]["type"] - The type of file being uploaded
$_files["file"]["size"] - Size of the uploaded file, in bytes
$_files["file"]["tmp_name"] - The name of the temporary copy of the file stored on the server
$_files["file"]["error"] - Error code caused by file upload


php code

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"] . "
";
}
else
{
echo "upload: " . $_files["file"]["name"] . "
";
echo "type: " . $_files["file"]["type"] . "
";
echo "size: " . ($_files["file"]["size"] / 1024) . " kb
";
echo "stored in: " . $_files["file"]["tmp_name"];
}
}
else
{
echo "invalid file";
}

?>

The contents of the $_files array are as follows:
$_files['myfile']['name'] The original name of the client file.
$_files['myfile']['type'] The mime type of the file, which requires the browser to provide support for this information, such as "image/gif".
$_files['myfile']['size'] The size of the uploaded file, in bytes.
$_files['myfile']['tmp_name'] The temporary file name stored on the server after the file is uploaded, usually the system default. It can be specified in upload_tmp_dir in php.ini, but setting it with the putenv() function has no effect.
$_files['myfile']['error'] Error codes related to the file upload. ['error'] was added in PHP 4.2.0 version. The following is its description: (They become constants after php3.0)
upload_err_ok
Value: 0; No errors occurred and the file was 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 was uploaded.
upload_err_no_file
Value: 4; No files were uploaded.
Value: 5; Upload file size is 0.


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445362.htmlTechArticle$_files[file][name] - the name of the uploaded file $_files[file][type] - is Type of uploaded file $_files[file][size] - Size of the uploaded file, in bytes $_files[file][tmp_name]...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template