simple php upload image, delete image implementation code
Upload Image:
if (!empty ($_files["img" ["name"])) {//Extract the file domain content name and determine $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 uploading of file formats $TP = Array ("Image/gif", "Image/pjpeg", "image/jpeg"); Check that the upload file is in the allowed upload type if (!in_array ($_files["img" ["type"], $TP)) {echo "<script>alert (' format not '); 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 ("Ymd His "); Gets the time and assigns a value to the 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 in particular that the first parameter passed to Move_uploaded_file is a temporary file uploaded to the server}//end IF//Here The value of $img is written 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 deleted pictures more concise than the ASP
The above is the PHP upload pictures, delete pictures Simple instance content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!