How to delete a zip file using php

人走茶凉 提交于 2019-12-02 13:26:21

Additionally you would have to change permissions to the zip, to make it writable first

chmod('./modules/'.$name.'.zip',0666);

666 = read / write for all Make sure that will return true. But since you cannot delete the file, most likely you will not be able to change it's permission also as Apache is not the owner.

777 for the parent directory is required only to write new files to that directory, do not affect operations that you can do with files that are already there.

$name = "zip_file_name";
$sPath = "./modules/" . $name . ".zip";
$aFilePath = explode("/", $sPath);
$i = 0;
$sLastFolder = "";
foreach ($aFilePath as $sFolder) {
    $i++;
    if (file_exists($sLastFolder . $sFolder) || is_dir($sLastFolder . $sFolder)) {
        $this->make_writeable($sLastFolder . $sFolder);
        $iOldumask = umask(0); // important part #1
        chmod($sLastFolder . $sFolder, 0777);
        umask($iOldumask); // important part #2
        $sLastFolder .= $sFolder . "/";
    }
}
unlink($sPath);
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!