Home >Backend Development >PHP Tutorial >Simple PHP file upload (example)_PHP tutorial
Save the following code as uploads.php
You uploaded a file:";
echo isset ($_FILES['upload_file']['name'])?$_FILES['upload_file']['name']:'';
echo "
";
//Client machine The original name of the file.
echo "The MIME type of the file is:";
echo isset($_FILES['upload_file']['type'])?$_FILES['upload_file']['type']:' ';
//The MIME type of the file, which requires the browser to provide support for this information, such as "image/gif".
echo "
";
echo "Upload file size:";
echo isset($_FILES['upload_file']['size'])?$_FILES['upload_file ']['size']:'';
//The size of the uploaded file, in bytes.
echo "
";
echo "The file is temporarily stored as:";
echo isset($_FILES['upload_file']['tmp_name'])?$ _FILES['upload_file']['tmp_name']:'';
//The temporary file name stored on the server after the file is uploaded.
$erroe = isset($_FILES['upload_file']['error'])?$_FILES['upload_file']['error']:'';
switch($erroe){
case 0:
echo "Upload successful"; break;
case 1:
echo "The uploaded file exceeds the value limited by the upload_max_filesize option in php.ini."; break;
case 2:
echo "The size of the uploaded file exceeds the value specified by the MAX_FILE_SIZE option in the HTML form."; break;
case 3:
echo "Only part of the file was uploaded"; break;
case 4:
echo "No files were uploaded"; break;
case 6:
echo "No cache directory"; break;
case 7:
echo "The upload directory is not readable"; break;
case 8:
echo "Upload stopped"; break;
default:
echo "No file uploaded"; break;
}
echo "