2
    <?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);不起作用 我对权限没有任何问题

该文件是否被写保护?如何解决这个问题?

谢谢朋友

4

1 回答 1

2

您上面的函数应该调用返回,而不是退出。Exit 终止脚本的执行,因此之后不会调用任何内容。它甚至可能没有到达 file_exists 部分。

于 2011-06-28T14:16:30.257 回答