程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> php 數據庫圖片信息及文件夾下的圖片刪除

php 數據庫圖片信息及文件夾下的圖片刪除

編輯:關於PHP編程

<?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> 
        <div id="main"> 
           後台管理->文章管理 
            <form  method="post" action="" > 
            <div 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> 
            </div> 
                    </form> 
        </div> 
    </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>
  <div id="main">
     後台管理->文章管理
      <form  method="post" action="" >
   <div 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>
   </div>
                    </form>
  </div>
 </body>
</html>


 

摘自 chaojie2009的專欄

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved