PHP upload pictures, delete pictures Simple instance _php instance

Source: Internet
Author: User

Simple PHP upload picture, delete picture implementation code

Upload Picture:

 if (!empty ($_files["img" ["name"])) {//Extract file Domain content name and judge $path = "uppic/";//upload path if (!file_exists 
($path)) 
{//Check if there is a folder, if it is not created, and give the highest permission mkdir ("$path", 0700); 
}//end IF//Allow uploaded file format $tp = Array ("Image/gif", "Image/pjpeg", "image/jpeg"); Check to see if the upload file is in the allowed upload type if (!in_array ($_files["img"] ["type"], $TP)) {echo "<script>alert (' malformed '); History.go (-1); 
</script> "; 
Exit 
}//end IF $filetype = $_files[' img ' [' type ']; 
if ($filetype = = ' Image/jpeg ') {$type = '. jpg '; 
} if ($filetype = = ' image/jpg ') {$type = '. jpg '; 
} if ($filetype = = ' Image/pjpeg ') {$type = '. jpg '; 
if ($filetype = = ' Image/gif ') {$type = '. gif '; } if ($_files["img" ["name"]) {$today =date ("Ymdhis");//Get time and assign value to variable $file 2 = $path. $today. $type//Picture full path $img = $tod Ay. $type; 
Picture name $flag = 1; 
}//end if ($flag) $result =move_uploaded_file ($_files["img"] ["Tmp_name"], $file 2); Special note Here The first parameter passed to Move_uploaded_file is the temporary file uploaded to the server}//end IF//Here then writes the $img value to the corresponding field in the database 

To delete a picture:

Unlink ("uppic/". $img); Of course, the value of the variable is read from the database, php delete pictures more concise than the ASP

Thank you for reading, I hope to help you, thank you for your support for this site!

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.