$_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.