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条)

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改