Upload image:
Copy code The code is as follows:
if (!empty($_FILES["img"]["name "])) { //Extract the file domain content name and determine
$path="uppic/"; //Upload path
if(!file_exists($path))
{
/ /Check whether the folder exists, if not, create it and give it the highest permissions
mkdir(“$path”, 0700);
}//END IF
//Allow uploaded file formats
$tp = array("image/gif","image/pjpeg","image/jpeg");
//Check whether the uploaded file is of a type that is allowed to be uploaded
if(!in_array($_FILES[ "img"]["type"],$tp))
{
echo "<script>alert('wrong format');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 the time and assign it to the variable
$file2 = $path.$today.$type; //Full path of the picture
$img = $today.$type; //Picture name
$flag=1;
}// END IF
if($flag) $result=move_uploaded_file($_FILES["img"]["tmp_name"],$file2);
//Specially note that the first parameter passed to move_uploaded_file here is upload To the temporary file on the server
}//END IF
//Here, write the value of $img to the corresponding field in the database
Delete the image:
Copy code The code is as follows:
unlink(“uppic/”.$img); //Of course, the value of the variable is from the database After reading it, PHP is much simpler to delete images than ASP
http://www.bkjia.com/PHPjc/321778.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/321778.htmlTechArticleUpload pictures: Copy the code as follows: if (!empty($_FILES["img"]["name" ])) { //Extract the file domain content name and determine $path="uppic/"; //Upload path if(!file_exists($path))...