Home>Article>Backend Development> PHP implementation of uploading and deleting images examples
Today, the editor will share with you a simple sample code for uploading pictures and deleting pictures in PHP. It is very simple and suitable for reference for beginners. It is also good for studying uploading pictures in PHP. Friends who are interested can learn about it.
1. PHP upload pictures:
alert(‘格式不对');history.go(-1);”; 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”); //获取时间并赋值给变量 $file2 = $path.$today.$type; //图片的完整路径 $img = $today.$type; //图片名称 $flag=1; }//END IF if($flag) $result=move_uploaded_file($_FILES["img"]["tmp_name"],$file2); //注意,此处传递给move_uploaded_file的第一个参数为上传到服务器上的临时文件 }//END IF //此处再将$img的值写入到数据库中对应的字段
2. PHP delete pictures:
##
1 Have you learned this? Is not it simple! Related tutorials:The above is the detailed content of PHP implementation of uploading and deleting images examples. For more information, please follow other related articles on the PHP Chinese website!