开发者

Download Form - Select files combile into Zip

Im looking to create a form where the user will select from a list of brochures. 10 in total.

They may only want to download 3 brochures, or 6, or 1, or 9, but the id开发者_JS百科ea being they select what brochures they want and then a script combiles a zip file containg the required brochures.

Can anyone suggest anything?


PHP has a Zip extension for this UseCase

Example from the manual page for ZipArchive::addFile

$zip = new ZipArchive;
if ($zip->open('test.zip') === TRUE) {
    $zip->addFile('/path/to/index.txt', 'newname.txt');
    $zip->close();
    echo 'ok';
} else {
    echo 'failed';
}

So, all you have to do is add the files the user selected to the ZipArchive and then send the Archive via header():

header('Content-type: application/zip');
header('Content-Disposition: attachment; filename="test.zip"');
readfile('test.zip');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜