Simple PHP upload image, delete image implementation code

Source: Internet
Author: User
Upload Image:

Copy the Code code as follows:


if (!empty ($_files["img" ["name"])) {//Extract the File field content name and determine
$path = "uppic/"; Upload path
if (!file_exists ($path))
{
Check if there is a folder, if not created, and give the highest permissions
mkdir ("$path", 0700);
}//end IF
Allow upload of file formats
$TP = Array ("Image/gif", "Image/pjpeg", "image/jpeg");
Check if the upload file is in a type that allows uploading
if (!in_array ($_files["img" ["type"], $TP))
{
echo "";
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 a value to a variable
$file 2 = $path. $today. $type; The full path of the picture
$img = $today. $type; Picture name
$flag = 1;
}//end IF
if ($flag) $result =move_uploaded_file ($_files["img" ["Tmp_name"], $file 2);
Note that the first parameter passed to Move_uploaded_file here is a temporary file uploaded to the server
}//end IF
The value of $img is then written to the corresponding field in the database


To delete a picture:

Copy the Code code as follows:


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

The above describes the simple PHP upload image, delete the image implementation code, including the content, I hope the PHP tutorial interested in a friend helpful.

  • Related Article

    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.