dongyixiu3110 2013-10-19 05:28
浏览 85
已采纳

从包含反斜杠的服务器中删除目录(PHP)

On my way to learning the mkdir(); function in PHP, I have created a folder on my server with a path like so

 files/New\\\\

Now, I can not delete this for the life of me... I found one other post that said I would need to use

 rmdir();

and escape the backslashes with more backslashes...

Needless to say, I can not get this to work... I had no idea that PHP added slashes through a post. I know from here forth I should use stripslashes(); but for now, I am stuck with two non deletable folders.

Any ideas guys?

  • 写回答

2条回答 默认 最新

  • doufan2541 2013-10-19 05:54
    关注

    Quick'n'dirty script:

    $filename = glob('../files/*');
    
    foreach($filename as $file) {
    
        print "'". $file. "' ";
        if(strstr($file,'New')) {
            if(is_file($file)) {
                unlink($file);
            }
        }
    }
    foreach($filename as $file) {
        if(strstr($file,'New')) {
            r_rmdir($file);
        }
    }
    
    function r_rmdir($dir) {
       if (is_dir($dir)) {
         $objects = scandir($dir);
         foreach ($objects as $object) {
           if ($object != "." && $object != "..") {
             if (filetype($dir."/".$object) == "dir") r_rmdir($dir."/".$object); else unlink($dir."/".$object);
           }
         }
         reset($objects);
         rmdir($dir);
       }
    

    }

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化