UPDATE: The embarrassing reason why it "didn't work" just was based on the fact that i was looking at the wrong directory.
I need to unlink/delete all files inside a folder. To achieve this, I have modified a method I've found here on 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;
}
}
}
The method works fine for all files, except for *.zip
files, as it seems. And what's even more strange about it: unlink()
still returns true without deleting the file.
Maybe the problem is related to my PHP version and/or the fact that it's running on a Windows Server.
Relevant specs:
PHP Version: 5.3.1
XAMPP Version: xampp-win32-1.7.3
OS: Windows 2008 Server
Any help would be appreciated.
The embarrassing reason why it "didn't work" just was based on the fact that i was looking at the wrong directory.