完成下载后删除文件

时间:2020-01-06 11:06:45

标签: php file download zip ziparchive

下载完成后如何删除文件。 我尝试使用unlink,但不起作用。我不知道,也许删除得太快了。

$zip = new ZipArchive();
$filename = "archive/myzipfiles.zip";   
if ($zip->open($filename, ZipArchive::CREATE)!==TRUE) {
    exit("cannot open <$filename>\n");
}
// Create zip
$dir = "download/pbr/1/resolution/2K/";
if (is_dir($dir)){
    if ($dh = opendir($dir)){
        while (($file = readdir($dh)) !== false){
            // If file
            if (is_file($dir.$file)) {
                if($file != '' && $file != '.' && $file != '..'){     
                    if($diffuse=="true"){
                        $zip->addFile($dir."diffuse".".".$format,"diffuse".".".$format);
                    }
                    if($roughness=="true"){
                        $zip->addFile($dir."roughness".".".$format,"roughness".".".$format); 
                    }
                    $zip->addFile("download/license.txt","license.txt"); //licence
                }
            }
        }
        closedir($dh);
    }
}
$zip->close();
echo $filename;

0 个答案:

没有答案