简体   繁体   中英

Delete existing zip file

I have a working code which can download all images from a website. I grab all the images, put them in a cache folder, create the zip file and download them. The problem what I can't solve is to delete the zip after I downloaded it. Here is my code:

foreach($image as $im){
    $info = explode('/',$im);
    $file_name = 'cache/'.$info[count($info)-1];
    copy($im,$file_name);
    $to_zip[] = $file_name;
}
// Zipping
$result = create_zip($to_zip,'kepek.zip');

// Clear cache
$files = glob('cache/*');
foreach($files as $file) if(is_file($file)) unlink($file);

// Download
Header('Location: kepek.zip');

Use unlink after the header

foreach($image as $im){
    $info = explode('/',$im);
    $file_name = 'cache/'.$info[count($info)-1];
    copy($im,$file_name);
    $to_zip[] = $file_name;
}
// Zipping
$result = create_zip($to_zip,'kepek.zip');

// Clear cache
$files = glob('cache/*');
foreach($files as $file) if(is_file($file)) unlink($file);

// Download
Header('Location: kepek.zip');
unlink('Location: kepek.zip');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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