Home>Article>Backend Development> Can php delete recorded pictures?

Can php delete recorded pictures?

藏色散人
藏色散人 Original
2021-11-12 09:18:53 1078browse

php can delete recorded pictures. The deletion method is: 1. Create a PHP file and connect to the database; 2. Delete through statements such as "Delete from test1 where id=".$rs['id'];" Just record the picture.

Can php delete recorded pictures?

The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer

php can be deleted Record pictures?

php Implementation code for deleting records and deleting picture files at the same time:

$cn = mysql_connect('127.0.0.1','root','root') or die('database connect fail'); mysql_select_db('test',$cn); mysql_query("set names 'gbk'"); /* 创建数据库教程 CREATE DATABASE `test` ; 创建数据表 test1 CREATE TABLE `test`.`test1` ( `id` INT( 4 ) NOT NULL AUTO_INCREMENT , `title` VARCHAR( 40 ) NULL DEFAULT '0', `litpic` VARCHAR( 100 ) NULL DEFAULT '0', PRIMARY KEY ( `id` ) ) ENGINE = MYISAM */ $sql = "Select * from test1 "; $query = mysql_query( $sql ) or die($sql); if( mysql_num_rows( $query ) ) { while( $rs = mysql_fetch_array( $query ) ) { $sql = "Delete from test1 where id=".$rs['id']; if( mysql_query( $sql ) ) { if( defile( $rs['litpic'] )) { echo '删除图片文件失败'; } else { echo '记录删除成功,并且删除了记录与相对应的图片或文件'; } } else { echo '记录不存删除数据与图片失败'; } } } else { echo '没有记录'; } /* @pare return #$url string 删除文件 */ function delfile($url) { if( file_exists($url) && is_file( $url ) ) { if( unlink( $url ) ) { return true; } else { return false; } } else { return false; } }

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of Can php delete recorded pictures?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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
Previous article:How to play sound in php Next article:How to play sound in php