繁体   English   中英

PHP取消链接无法取消链接zip文件-仍然返回true

[英]PHP unlink fails to unlink zip-file - still returns true

更新:为什么它“无法正常工作”的尴尬原因只是基于我查看错误目录的事实。

我需要取消链接/删除文件夹中的所有文件。 为此,我修改了在SO上找到的一种方法:

public function deleteDirContent($dirPath)
{
    if (!is_dir($dirPath)) 
    {
        throw new InvalidArgumentException("$dirPath must be a directory");
    }
    if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') 
    {
        $dirPath .= '/';
    }
    $files = glob($dirPath . '*', GLOB_MARK);
    foreach ($files as $file) 
    {
        if (is_dir($file)) 
        {
            $this->deleteDirContent($file);
        } 
        else 
        {
            print_r($file);
            if(unlink($file))
            {
                echo " - SUCCESS";
            }
            else
            {
                echo " - ERROR !";
            }
            echo PHP_EOL;
        }
    }
}

看起来,该方法适用于所有文件,但*.zip文件除外。 甚至更奇怪的是: unlink()仍返回true而不删除文件。

也许问题与我的PHP版本和/或它在Windows Server上运行有关。

相关规格:

PHP版本: 5.3.1
XAMPP版本: xampp-win32-1.7.3
操作系统: Windows 2008 Server


任何帮助,将不胜感激。

尝试使用chmod更改权限:

// Read and write for owner, nothing for everybody else
chmod("/somedir/somefile", 0600);

它“无法正常工作”的尴尬原因只是基于我查看错误的目录这一​​事实。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM