<form action= "" enctype= "Multipart/form-data" method= "POST"
Name= "UploadFile" > Upload file: <input type= "file" Name= "Upfile"/><br>
<input type= "Submit" value= "Upload"/></form>
<?php
Print_r ($_files["Upfile"]);
if (Is_uploaded_file ($_files[' upfile ' [' tmp_name '])) {
$upfile =$_files["Upfile"];
Gets the value inside the array
$name = $upfile ["name"];//the filename of the uploaded file
$type = $upfile ["type"];//types of uploaded files
$size = $upfile ["Size"];//upload files
$tmp _name= $upfile ["Tmp_name"];//the temporary storage path of the uploaded file
Determine if it is a picture
Switch ($type) {
Case ' image/pjpeg ': $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 Upload success <br/>
* 1: Over file size, set in php.ini file <br/>
* 2: exceeds the file size max_file_size the value specified by the option <br/>
* 3: Files are only partially uploaded <br/>
* 4: No files are uploaded <br/>
* 5: Upload file size is 0
*/
$error = $upfile ["Error"];//the value returned by the system after uploading
echo "================<br/>";
echo "Upload file name is:". $name. " <br/> ";
echo "Upload file type is:". $type. " <br/> ";
echo "Upload file size is:". $size. " <br/> ";
echo "The value returned by the system after uploading is:". $error. " <br/> ";
echo "The temporary storage path for uploading files is:". $tmp _name. " <br/> ";
echo "Start moving upload file <br/>";
Move the uploaded temporary files to the up directory
Move_uploaded_file ($tmp _name, ' up/'. $name);
$destination = "up/". $name;
echo "================<br/>";
echo "Upload information:<br/>";
if ($error ==0) {
echo "File Upload succeeded! ";
echo "<br> picture preview:<br>";
echo " ";
echo "alt=\" Picture preview: \ r file name: ". $destination." \ r upload time: \ ">";
}elseif ($error ==1) {
echo "Exceeds file size, set in php.ini file";
}elseif ($error ==2) {
echo "exceeded the file size max_file_size option specified value";
}elseif ($error ==3) {
echo "file is only partially uploaded";
}elseif ($error ==4) {
echo "No files were uploaded";
}else{
echo "Upload file size is 0";
}
}else{
echo "Please upload pictures in jpg,gif,png and other formats!" ";
}
}
?>
In the fileupload.php file:
.The code is as follows:
Determine if it is a picture
Switch ($type) {
Case ' image/pjpeg ': $okType =true;
Break
Case ' image/jpeg ': $okType =true;
Break
Case ' image/gif ': $okType =true;
Break
Case ' image/png ': $okType =true;
Break
}
Above is to determine whether the file is a picture type, more file types, you can refer to the Tomcat/conf/web.xml file, the file type is very full ....
PHP File Upload Instance code