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


PHP unlink fails to unlink zip-file - still returns true

UPDATE:它"不起作用"的尴尬原因只是基于我看错了目录的事实。

我需要取消链接/删除文件夹中的所有文件。为了实现这一点,我修改了我在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服务器上运行的事实有关。

相关规格:

PHP 版本: 5.3.1
XAMPP版本:xampp-win32-1.7.3
操作系统:视窗 2008 服务器


任何帮助将不胜感激。

尝试使用 chmod 更改权限:

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

它"不起作用"的尴尬原因只是基于我看错了目录的事实。