【问题标题】:PHP Delete a file into a folderPHP 将文件删除到文件夹中
【发布时间】:2015-08-16 14:31:15
【问题描述】:

我正在尝试根据用户的操作将特定文件名删除到文件夹中,我收到以下警告:

警告:unlink(): http 不允许取消链接

这是具有提供到 deleteRecord.php 导航的按钮的代码

> <script>                                                  //btn delete
>         $(".btn_delete").click(function(){
>           var id = $(this).closest('tr').children('td:first').text();
>             //alert(id);                                          
>               var x;
                if (confirm("Are you sure you want delete this record?") == true) {
>                //alert ("You pressed OK!");                                                       
>               
>               location.href='deleteRecord.php?filename='+filename;
>                   } else {
>                       //alert ("You pressed Cancel!");
>                       return false;           }
>         });
>     </script>

这项工作非常好,我把它展示到变量 id 来自哪里

现在这是返回警告的 php 页面:

$filename = $_GET['filename']; //get the filename like "yo.jpg"

$path = "http://www.here I have the exact address to the folder/";

unlink($path . '/' . $filename);

这个结果我再放一遍!

******警告:unlink(): http 不允许在******中取消链接

有什么建议吗?有什么建议吗?请原谅我的英语,我正在学习!

【问题讨论】:

  • 您无法取消链接 URL。您取消链接文件系统上的文件。
  • http://yoursite.com/delete.php?file=/etc/passwd 清理并验证您的输入。

标签: php html directory


【解决方案1】:

您需要将服务器的路径作为参数传递给unlink()而不是URL,例如:

unlink('/var/www/mywebsite.com/images/myimage.jpg')

【讨论】:

    猜你喜欢
    • 2020-08-19
    • 1970-01-01
    • 2011-04-07
    • 2013-03-20
    • 1970-01-01
    • 2015-04-24
    • 1970-01-01
    • 2010-11-24
    • 1970-01-01
    相关资源
    最近更新 更多