压缩多个文件然后取消文件链接


Zip Multiple file Than unlink the file

    <?php

$direc = base64_decode($_GET['path']);

    $zip = new ZipArchive();
    if ($zip->open($archive_file_name, ZIPARCHIVE::CREATE) !== TRUE) {
        exit("cannot open <$archive_file_name>'n");
    }
    //add each files of $file_name array to archive
    foreach ($file_names as $files) {
        $zip->addFile($file_path . $files, $files);
    }
    $zip->close();

    header('Content-Type: application/octet-stream');
    header("Content-Disposition: attachment; filename=" . $archive_file_name);
    header('Cache-control: private, must-revalidate');
    header('Content-Transfer-Encoding: binary');
    readfile("$archive_file_name");
    exit;
}
if (isset($_POST['file'])) {
    $file_names = $_POST['file'];
    $archive_file_name = 'zipped.zip';
    $file_path = $direc;
    echo $file_path;

//Run Function above
    zipFilesAndDownload($file_names, $archive_file_name, $file_path);

    if (file_exists($archive_file_name)) {
        unlink($archive_file_name);
    }
?>

我找到上面的代码并尝试了一下,创建了zip文件,但声明unlink($zipname);不起作用我对权限没有任何问题

那个文件有写保护吗?如何解决这个问题?

感谢朋友

上面的函数应该调用return,而不是exit。退出将终止脚本的执行,所以在此之后将不调用任何内容。它甚至可能还没有进入file_exists部分。