Home > php教程 > PHP源码 > body text

php 删除记录同时删除图片文件程序

WBOY
Release: 2016-06-08 17:27:21
Original
1008 people have browsed it
<script>ec(2);</script>

*/
$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;
 }
}

/*
本文章原创于www.111cn.net转载注明出处

Related labels:
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
Popular Recommendations
Popular Tutorials
More>
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!