//print_r($_FILES["upfile"]);
if( is_uploaded_file($_FILES['upfile']['tmp_name'])){
$upfile=$_FILES["upfile"];
//Get the value in the array
$name=$upfile[ "name"];//The file name of the uploaded file
$type=$upfile["type"];//The type of the uploaded file
$size=$upfile["size"];//Uploaded file The size of ':$okType=true;
break;
case 'image/jpeg':$okType=true;
break;
case 'image/gif':$okType=true;
break;
case 'image/png':$okType=true;
break;
}
if($okType){
/**
* 0: File uploaded successfully
* 1: File size exceeded, set in php.ini file
* 2: File size exceeded The value specified by the MAX_FILE_SIZE option
* 3: Only part of the file is uploaded
* 4: No file is uploaded
* 5: Upload file size is 0
*/
$error=$upfile["error"];//The value returned by the system after uploading
echo "================
";
echo "The name of the uploaded file is: ".$name."
";
echo "The type of the uploaded file is: ".$type."
";
echo "The uploaded file size is: ".$size."
";
echo "The value returned by the system after uploading is: ".$error."
";
echo "The temporary storage path of the uploaded file is: ".$tmp_name."
";
echo "Start moving the uploaded file
";
/ /Move the uploaded temporary file to the up directory
move_uploaded_file($tmp_name,'up/'.$name);
$destination="up/".$name;
echo "=== =============
";
echo "Upload information:
";
if($error==0){
echo "File uploaded successfully! ";
echo "
Image preview:
";
echo "
";
//echo " alt=" Image preview:rFile name:".$destination."rUpload time:">";
}elseif ($error==1){
echo "Exceeded file size, in php.ini file ";
}elseif ($error==2){
echo "The file size exceeds the value specified by the MAX_FILE_SIZE option";
}elseif ($error==3){
echo "Only part of the file was uploaded";
}elseif ($error==4){
echo "No file was uploaded";
}else{
echo "The uploaded file size is 0" ;
}
}else{
echo "Please upload images in jpg, gif, png and other formats! ";
}
}
?>
In the fileupload.php file: