【问题标题】:Not able to delete the directory in php 5.6+?无法删除 php 5.6+ 中的目录?
【发布时间】:2018-12-27 17:05:47
【问题描述】:

我正在尝试删除 PHP 5.6+ 中的目录文件夹,但抛出显示 Uncaught exception 'InvalidArgumentException' with message ' must be a directory 的异常。

 <?php
 $pcode="gfhfh";
 $dir = "http://127.0.0.1/".$pcode;
 if (is_dir($dir)) { 
 $objects = scandir($dir); 
 foreach ($objects as $object) { 
   if ($object != "." && $object != "..") { 
     if (is_dir($dir."/".$object))
       rrmdir($dir."/".$object);
     else
       unlink($dir."/".$object); 
   } 
 }
 rmdir($dir); 
 } else {

   throw new InvalidArgumentException("$dirPath must be a directory");
 } 

?>

【问题讨论】:

  • 为什么要通过http删除文件夹?你不应该删除一个本地文件夹吗?
  • 我该怎么做?
  • 好吧,不要在目录前加上http,而是使用本地文件夹——你最好再考虑一下删除哪个文件夹
  • 我要删除“gfhfh”文件夹?

标签: php html php-5.6


【解决方案1】:

我得到了改变路径的答案(“/applications/ampps/www/”)

<?php
$pcode="gfhfh";
$dir = "/applications/ampps/www/".$pcode;
if (is_dir($dir)) { 
$objects = scandir($dir); 
foreach ($objects as $object) { 
if ($object != "." && $object != "..") { 
 if (is_dir($dir."/".$object))
   rrmdir($dir."/".$object);
 else
   unlink($dir."/".$object); 
} 
}
 rmdir($dir); 
 } else {

 throw new InvalidArgumentException("$dirPath must be a directory");
 } 

?>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-09
    • 1970-01-01
    • 2012-04-03
    • 2021-01-01
    • 1970-01-01
    相关资源
    最近更新 更多