1. 云栖社区>
  2. PHP教程>
  3. 正文

php 数据库图片信息及文件夹下的图片删除

作者:用户 来源:互联网 时间:2017-12-01 19:07:16

图片文件夹php数据库

php 数据库图片信息及文件夹下的图片删除 - 摘要: 本文讲的是php 数据库图片信息及文件夹下的图片删除, <?php /** *图片管理 * 2011/8/20 * kcj * */ include "isLogin.php";   ?> <html>     <head>         <meta

<?php 
/**
 *图片管理
 * 2011/8/20
 * kcj
 * */ 
include "isLogin.php"; 
 
 
?> 
<html
    <head> 
        <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 
        <title>后台管理</title> 
        <meta name="Author" content="kcj" /> 
        <meta name="Keywords" content="php,lampbrother" /> 
        <link rel="stylesheet" type="text/css" href="style/lampcms.css"> 
        <script src="javascript/common.js"></script> 
    </head> 
    <body> 
        <p id="main"> 
           后台管理->文章管理 
            <form  method="post" action="" > 
            <p class="msg-box"> 
                <ul class="viewmess"> 
 
                 <li class="dark-row"> 
 
                     
                        <span class="list_width width_font">图片名称</span> 
                        <span class="list_width width_font">图片路径</span> 
                        <span class="list_width width_font">添加时间</span> 
                        <span class="list_width width_font">操作</span> 
 
                    </li> 
   
                        <?php 
                        /**
                         * 图片管理
                         * 2011/8/20
                         * kcjs
                         **/ 
                        require "../conn/conn.php"; 
                        if($_GET["del"]){                   //删除图片信息及文件夹下的图片(注意不要犯逻辑性的错误,当然可以分开写这两个的删除)  
                            $id=$_GET["del"]; 
                            $sql2="select*from pic where id=".$id; 
                            $rst2=mysql_query($sql2); 
                            $row=mysql_fetch_array($rst2);  
                            $sql="delete from pic where id=".$id; 
                            mysql_query($sql); 
                            $filename=$row['picpath']; 
                            if(file_exists($filename)){ 
                                unlink($filename); 
                            }else { 
                                echo "图片路径不正确"; 
                            } 
                             
                        } 
 
                        $sql="select*from pic"; 
                        $rst=mysql_query($sql); 
                        $totalnum=mysql_num_rows($rst); //print_r($totalnum);exit;  
                        $pagenum=5; 
                        $page=$_GET["page"]; 
                        if($page==" "){ 
                            $page=1; 
                        } 
                        $begin=($page-1)*$pagenum; 
                        $pagecount=ceil($totalnum/$pagenum); 
                        $sql2="select * from pic order by id desc limit ".$begin.",".$pagenum." "; 
                        $rst2=mysql_query($sql2); 
                        while (@$row=mysql_fetch_array($rst2)){ 
                        ?> 
 
                 <li class="light-row" style="padding-top:2px; padding-bottom:2px"> 
      
                         
                        <span class="list_width width_font"><a href="" target="_blank"><?php echo $row["picname"];?></a></span> 
                        <span class="list_width width_font"><?php echo $row["picpath"];?></span> 
                        <span class="list_width width_font"><?php echo $row["ctime"];?></span> 
                        <span class="list_width width_font"><a href="editUpload.php?edit=<?php echo $row[id];?>">【修改】</a><a href="listUpload.php?del=<?php echo $row[id];?>">【删除】</a></span> 
                   
                     
          
                    <?php 
                        } 
                    ?> 
            
                 
    <li class="dark-row"> 
                        <span class="right"> 
 
 
                            共<?php echo $totalnum;?>条 ;共<?php echo $pagecount;?>页;每页显示<?php echo $pagenum;?>条 
 
                                <a href="<?php echo $_SERVER['PHP_SELF']?>?page=1">首页</a>   
 
                                <a href="<?php echo $_SERVER['PHP_SELF']?>?page=<?php  if($page>1) echo  $page-1; else  echo $page=1;?>">上一页</a>   
 
 
 
 
 
                                <a href="<?php echo $_SERVER['PHP_SELF']?>?page=<?php if($page<$pagecount-1) echo $page+1; else echo $pagecount; ?>">下一页</a>   
 
 
 
                                <a href="<?php echo $_SERVER['PHP_SELF']?>?page=<?php echo $pagecount;?>">尾页</a>   
 
                        </span> 
                    </li> 
                </ul> 
            </p> 
                    </form> 
        </p> 
    </body> 
</html> 
<?php
/**
 *图片管理
 * 2011/8/20
 * kcj
 * */
include "isLogin.php";


?>
<html>
 <head>
  <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
  <title>后台管理</title>
  <meta name="Author" content="kcj" />
  <meta name="Keywords" content="php,lampbrother" />
  <link rel="stylesheet" type="text/css" href="style/lampcms.css">
  <script src="javascript/common.js"></script>
 </head>
 <body>
  <p id="main">
     后台管理->文章管理
      <form  method="post" action="" >
   <p class="msg-box">
    <ul class="viewmess">

                 <li class="dark-row">

     
                     <span class="list_width width_font">图片名称</span>
      <span class="list_width width_font">图片路径</span>
      <span class="list_width width_font">添加时间</span>
      <span class="list_width width_font">操作</span>

     </li>
 
            <?php
            /**
             * 图片管理
             * 2011/8/20
             * kcjs
             **/
            require "../conn/conn.php";
            if($_GET["del"]){                   //删除图片信息及文件夹下的图片(注意不要犯逻辑性的错误,当然可以分开写这两个的删除)
             $id=$_GET["del"];
                $sql2="select*from pic where id=".$id;
             $rst2=mysql_query($sql2);
             $row=mysql_fetch_array($rst2);
                $sql="delete from pic where id=".$id;
                mysql_query($sql);
                $filename=$row['picpath'];
                if(file_exists($filename)){
                 unlink($filename);
                }else {
                 echo "图片路径不正确";
                }
             
            }

            $sql="select*from pic";
            $rst=mysql_query($sql);
            $totalnum=mysql_num_rows($rst); //print_r($totalnum);exit;
            $pagenum=5;
            $page=$_GET["page"];
            if($page==" "){
             $page=1;
            }
            $begin=($page-1)*$pagenum;
            $pagecount=ceil($totalnum/$pagenum);
            $sql2="select * from pic order by id desc limit ".$begin.",".$pagenum." ";
            $rst2=mysql_query($sql2);
            while (@$row=mysql_fetch_array($rst2)){
            ?>

                 <li class="light-row" style="padding-top:2px; padding-bottom:2px">
    
        
                     <span class="list_width width_font"><a href="" target="_blank"><?php echo $row["picname"];?></a></span>
      <span class="list_width width_font"><?php echo $row["picpath"];?></span>
      <span class="list_width width_font"><?php echo $row["ctime"];?></span>
      <span class="list_width width_font"><a href="editUpload.php?edit=<?php echo $row[id];?>">【修改】</a><a href="listUpload.php?del=<?php echo $row[id];?>">【删除】</a></span>
                 
     
        
     <?php
            }
     ?>
          
    
 <li class="dark-row">
      <span class="right">


                            共<?php echo $totalnum;?>条 ;共<?php echo $pagecount;?>页;每页显示<?php echo $pagenum;?>条

        <a href="<?php echo $_SERVER['PHP_SELF']?>?page=1">首页</a> 

        <a href="<?php echo $_SERVER['PHP_SELF']?>?page=<?php  if($page>1) echo  $page-1; else  echo $page=1;?>">上一页</a> 

 

 

        <a href="<?php echo $_SERVER['PHP_SELF']?>?page=<?php if($page<$pagecount-1) echo $page+1; else echo $pagecount; ?>">下一页</a> 

 

        <a href="<?php echo $_SERVER['PHP_SELF']?>?page=<?php echo $pagecount;?>">尾页</a> 

      </span>
     </li>
    </ul>
   </p>
                    </form>
  </p>
 </body>
</html>


 

摘自 chaojie2009的专栏

以上是云栖社区小编为您精心准备的的内容,在云栖社区的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索图片 , 文件夹 php数据库 ,以便于您获取更多的相关知识。