因此,我创建了一些php代码来使用ZipArchive创建zip文件。这将创建一个zip文件并下载它。要启动下载,我将包含下面php代码的php文件链接放在iframe中。然后将此iframe插入到html文档中。重新下载zip文件而不重写zip文件 - ZipArchive PHP
因此,无论何时加载html文档,下载器都会启动。我在iframe标记中创建了onload属性,它将调用一个函数来显示重新下载按钮。
因此,如果用户单击重新下载按钮,我希望它再次下载同一个zip文件,但不能再次重新创建zip文件进程。我怎么做?
谢谢!
我的HTML代码:
<iframe src="phpfile.php" onload="myFrameLoad(this)"></iframe>
为phpfile.php我的PHP代码:
$coreFiles = Array('blah.jpg', 'blo.png');
# create new zip object
$coreZip = new ZipArchive();
# create a temp file & open it
$tmp_file = tempnam('.','');
$coreZip->open($tmp_file, ZipArchive::CREATE);
# loop through each file
foreach($coreFiles as $coreFile){
# download file
$download_file = file_get_contents($coreFile);
#add it to the zip
$coreZip->addFromString(basename($coreFile),$download_file);
}
# close zip
$coreZip->close();
# send the file to the browser as a download
header('Content-disposition: attachment; filename=myZipFolder.zip');
header('Content-type: application/zip');
readfile($tmp_file);
你就必须存储的地方解压缩文件。并在调用ZipArchive之前先查找它。是的,这会在一段时间后占用大量空间 – Forbs
_“因此,无论何时加载html文档,下载程序都会启动”_,_“因此,如果用户单击重新下载按钮”_位于哪里“重新下载按钮”? – guest271314
@ guest271314重新下载按钮将出现在HTML文档中的iframe上方 –