-
-
- /**
- * When deleting records, picture files will also be deleted
- * by bbs.it-home.org
- */
- $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 tutorial
- CREATE DATABASE `test`;
- Create data table 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 'Failed to delete picture file';
- }
- else
- {
- echo 'The record was deleted successfully, and the record and the corresponding picture or file were deleted';
- }
- }
- else
- {
- echo 'Record not saved, failed to delete data and pictures';
- }
- }
- }
- else
- {
- echo 'No record';
- }
- /*
- @pare return
- #$url string
- Delete file
- */
- function delfile($url)
- {
- if( file_exists($url) && is_file( $url ) )
- {
- if( unlink( $url ) )
- {
- return true;
- }
- else
- {
- return false ;
- }
- }
- else
- {
- return false;
- }
- }
Copy code
>>>> Articles you may be interested in:
php delete uploaded pictures and folders (example sharing)
Simple sample code for uploading and deleting images in PHP
Small example of PHP deleting all files created N minutes ago
Example of how to delete a directory and all files in php
An example of php code to delete all files in a directory N days ago
php implementation code for deleting records and refreshing the current page
Delete the php code of all files in the specified folder
Simple example of uploading and deleting images in php
A function written in php to delete a directory
php code for recursively creating and deleting folders
php custom function rrmdir to recursively delete directories and files
Example of php recursively deleting directories
|