Home > Backend Development > PHP Tutorial > 关于删除文件的绝对路径有关问题 求指点

关于删除文件的绝对路径有关问题 求指点

WBOY
Release: 2016-06-13 13:42:20
Original
785 people have browsed it

关于删除文件的绝对路径问题 求指点

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->  delete_files.php
$dir = "uploadfiles";//设置文件保存目录 注意包含/
   $id=$_GET['delete'];
    $conn=mysql_connect('localhost','root','');
    $flag=mysql_select_db('laborder' ,$conn);
    mysql_query("set names utf8");
    $sql="select * from files where files_id='$id'";
    $sqlupdate="delete from student where student_id='$id'";
     $result=mysql_query($sql,$conn);
         if($lists=mysql_fetch_array($result))
         { $name=$lists['files_name'];
           $a=dirname(__FILE__);
           $i=unlink($a/$dir/$name);
                  if(mysql_query($sqlupdate)&&$i)
                  {   
                      
                       echo" <script type="text/javascript">"
                      ."txtOption='删除成功!';".
                      "alert(txtOption);";
                       echo "</script>";  
                       echo "<script>window.location.href='admin_files.php';</script>";
                       
                  }
         }
Copy after login

这是我做的删除文件的代码,删除文件的同时把他的名称从数据库中删除,现在无法实现删除文件,unlink删除文件时绝对路径吧,用dirname(__FILE__)取得本文件的据对路径,$dir是要删除的文件所在文件夹,请问哪里不对,新手求指点。文件结构是www/test5/uploadfiles/要删除文件 www/test5/delete_files.php本文件



------解决方案--------------------
先把 $a/$dir/$name 这个echo看看,地址对不
------解决方案--------------------
PHP code
$xxx = "{$a}/{$dir}/{$name}";
echo $xxx;
unlink($xxx);
<br><font color="#e78608">------解决方案--------------------</font><br>路径要对,权限要有,必须是个文件
<br><font color="#e78608">------解决方案--------------------</font><br>
Copy after login
探讨
E:\work\wamp\www\test5/uploadfiles/SOBEL算子.doc}
按照3楼的更改居然有这个警告
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template