How to delete uploaded pictures in php

藏色散人
Release: 2023-03-03 14:08:01
Original
3047 people have browsed it

php method to delete uploaded images: first check whether the uploaded file is of a type that is allowed to be uploaded; then get the full path of the image; finally delete the image through the "unlink("uppic/".$img);" method That’s it.

How to delete uploaded pictures in php

Recommended: "PHP Video Tutorial"

Simple PHP sample code for uploading images and deleting images

Share a simple sample code for uploading images and deleting images in PHP. It is very simple and suitable for reference for beginners. It is also good for studying uploading images in PHP.

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的值写入到数据库中对应的字段
Copy after login

2. PHP delete pictures:


        
Copy after login

The above is the detailed content of How to delete uploaded pictures in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!