PHP Upload Files

Source: Internet
Author: User

* 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.