* time:11:47
*/
if (Isset ($_post[' submit '))
{
File storage Path
$file _path= "upload/";
664 permissions are file owners and group users can read and write, other users are read-only.
if (Is_dir ($file _path)!=true) mkdir ($file _path,0664);
Define the file extensions that are allowed to be uploaded
$ext _arr = Array ("GIF", "JPG", "JPEG", "PNG", "BMP", "txt", "zip", "rar");
if (empty ($_files) = = = False) {
Judgment check
if ($photo _up_size > 2097152) {
Exit ("Sorry, you have uploaded more than 2M photos. ");
}
if ($_files["file" ["error"] > 0) {
Exit ("File Upload error:". $_files["Files"] ["error"]);
}
Get file name extension
$temp _arr = Explode (".", $_files["file" ["name"]);
$file _ext = Array_pop ($temp _arr);
$file _ext = Trim ($file _ext);
$file _ext = strtolower ($file _ext);
Check extension
if (In_array ($file _ext, $ext _arr) = = = = False) {
Exit ("The upload file name extension is not allowed. ");
}
Rename a file with a timestamp
$new _name = time (). ".". $file _ext;
Move files to the storage directory
Move_uploaded_file ($_files["file"] ["Tmp_name"], "$file _path". $new _name);
Write file storage information to a data table to manage
Code slightly ***********//
echo "File Upload successful! ";
Exit
} else {
echo "No file upload is correct";
}
}
?>
<form enctype= "Multipart/form-data" action= "upload.php" method= "POST" >
<label for= "File" > Please select File to upload </label>
<input type= "File" name= "file" size= "/>"
<br/>
<input type= "Submit" name= "Submit" value= "OK"/>
</form>
PHP Upload Files