php堆栈溢出,php - 内拉链(PHP) - 堆栈内存溢出

问题编号1:

您无法在空的zip档案中创建空的zip档案。 这将导致文件损坏。

问题编号2:

在您尚未关闭第一个zip存档的情况下,请勿尝试将其添加到另一个zip存档。

问题编号3:

$Bzip->addFile($file_path.$SzipN,$Szip); 那么,为什么要尝试将对象设置为文件名呢? => $Szip = new ZipArchive();

解:

//Big and Small Archives names

$BzipN='Bigzip.zip';

$SzipN='Smallzip.zip';

//Big and Small Archives

$Bzip = new ZipArchive();

$Szip = new ZipArchive();

//File path

$file_path=$_SERVER['DOCUMENT_ROOT'].'/PF/';

function zipFilesAndDownload($BzipN,$SzipN,$Bzip,$Szip,$file_path){

// Create the file Smallzip.zip and throw the error if unsuccessful

if ($Szip->open($SzipN, ZIPARCHIVE::CREATE )!==TRUE) {

exit("cannot open \n");

}

// Add a txt file to Smallzip so it isn't empty

$Szip->addFromString("testfilephp.txt", "#1 This is a test string added as testfilephp.txt.\n");

// Close Smallzip.zip as we're done with it

$Szip->close();

// Create the file Bigzip.zip and throw the error if unsuccessful

if ($Bzip->open($BzipN, ZIPARCHIVE::CREATE )!==TRUE) {

exit("cannot open \n");

}

// Add Smallzip.zip to Bigzip.zip with a valid name

$Bzip->addFile($file_path.$SzipN,$SzipN);

// Close Bigzip.zip as we're done with it

$Bzip->close();

//then send the headers to foce download the Big zip file

header("Content-type: application/zip");

header("Content-Disposition: attachment; filename=$BzipN");

header("Content-length: " . filesize($BzipN));

header("Pragma: no-cache");

header("Expires: 0");

readfile("$BzipN");

// Delete the files from the server, even if the user cancels the download

ignore_user_abort(true);

unlink($file_path.$SzipN);

unlink($file_path.$SzipN);

exit;

}

zipFilesAndDownload($BzipN,$SzipN,$Bzip,$Szip,$file_path);

?>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值