开发者

Download Form - Select files combile into Zip

开发者 https://www.devze.com 2022-12-15 13:55 出处:网络
Im looking to create aform 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

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

精彩评论

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