N Multi-disk zip archives not supported - php

i want to download file to zip using php zipArchive but i am getting this error
'N Multi-disk zip archives not supported'.

$file_names is the array of files which you want to add in the zip
function zipFile($file_names,$archive_file_name)
{
$zip = new ZipArchive();
//create the file and throw the error if unsuccessful
if ($zip->open($archive_file_name, ZIPARCHIVE::OVERWRITE )!==TRUE) {
}
//add each files of $file_name array to archive
foreach($file_names as $files)
{
// $zip->addFile($files,$files);
$zip->addFromString(basename($files), file_get_contents($files));
}
$zip->close();
}

Related

How to create a zipfile with child zipFiles in php

i need to create a zipFile with a childs zipFiles already exist :
> folder
- file1.zip
- file2.zip
I want to get a zip file containing all the zip files in the folder.
$dir = "path/to/my/dir";
$finder = new Finder();
$zip = new \ZipArchive();
/***** I create a empty zip file ****/
$filesystem->dumpFile("$dir/delivrables.zip",'');
if($zip->open('delivrables.zip', ZipArchive::CREATE) === TRUE) {
foreach ($finder->in($dir) as $file) {
$zip->addFile($file->getPath(), $file->getFilename());
}
}
I don't get error but i can't extract zip file.
You can create a zip file with zip files in the same way as you create a zip file with images, documents etc

PHP Download Multiple Files in Zip folder [duplicate]

How can I download multiple files as a zip-file using php?
You can use the ZipArchive class to create a ZIP file and stream it to the client. Something like:
$files = array('readme.txt', 'test.html', 'image.gif');
$zipname = 'file.zip';
$zip = new ZipArchive;
$zip->open($zipname, ZipArchive::CREATE);
foreach ($files as $file) {
$zip->addFile($file);
}
$zip->close();
and to stream it:
header('Content-Type: application/zip');
header('Content-disposition: attachment; filename='.$zipname);
header('Content-Length: ' . filesize($zipname));
readfile($zipname);
The second line forces the browser to present a download box to the user and prompts the name filename.zip. The third line is optional but certain (mainly older) browsers have issues in certain cases without the content size being specified.
This is a working example of making ZIPs in PHP:
$zip = new ZipArchive();
$zip_name = time().".zip"; // Zip name
$zip->open($zip_name, ZipArchive::CREATE);
foreach ($files as $file) {
echo $path = "uploadpdf/".$file;
if(file_exists($path)){
$zip->addFromString(basename($path), file_get_contents($path));
}
else{
echo"file does not exist";
}
}
$zip->close();
Create a zip file, then download the file, by setting the header, read the zip contents and output the file.
http://www.php.net/manual/en/function.ziparchive-addfile.php
http://php.net/manual/en/function.header.php
You are ready to do with php zip lib,
and can use zend zip lib too,
<?PHP
// create object
$zip = new ZipArchive();
// open archive
if ($zip->open('app-0.09.zip') !== TRUE) {
die ("Could not open archive");
}
// get number of files in archive
$numFiles = $zip->numFiles;
// iterate over file list
// print details of each file
for ($x=0; $x<$numFiles; $x++) {
$file = $zip->statIndex($x);
printf("%s (%d bytes)", $file['name'], $file['size']);
print "
";
}
// close archive
$zip->close();
?>
http://devzone.zend.com/985/dynamically-creating-compressed-zip-archives-with-php/
and there is also php pear lib for this
http://www.php.net/manual/en/class.ziparchive.php

Download Images with zip File

I am generating dynamic images from API.
And on button click i want to download a zip file with images .
I tried many solution, but still not able to download zip file with images
$zip = new ZipArchive();
$zip_name = time().".zip"; // Zip name
$zip->open($zip_name, ZipArchive::CREATE);
foreach ($files as $file) {
echo $path = "uploadpdf/".$file;
if(file_exists($path)){
$zip->addFromString(basename($path),file_get_contents($path));
}else {
echo"file does not exist";
}
}
$zip->close()

fails with ZipArchive

i will create a Zip Archive with the PHP Class. But it still not working.
It comes no fail and the response is 1. He don't create the Zip-File.
$zip = new ZipArchive;
$res = $zip->open('qr_img/'.'ab387bas.zip'.'', ZipArchive::CREATE);
if ($res === TRUE) {
$zip->addFile($file, 'screen.png');
$zip->close();
}
know's everyone the answer ?
$file_names is the array of files which are you want to add in the zip.
function zipFile($file_names,$archive_file_name)
{
$zip = new ZipArchive();
//create the file and throw the error if unsuccessful
if ($zip->open($archive_file_name, ZIPARCHIVE::OVERWRITE )!==TRUE) {
}
//add each files of $file_name array to archive
foreach($file_names as $files)
{
// $zip->addFile($files,$files);
$zip->addFromString(basename($files), file_get_contents($files));
}
$zip->close();
}

Dynamically creating zip with php

What is the easiest way of creating dynamically zip files with php?
For example,
I have these files on the server,
Root -> Folder 1 -> file1.wav
Root -> Folder 2 -> file2.jpg
I want to create a zip file contains these 2 files and allow user to download it.
any help ?
Thx in advance
See the ZipArchive class; it has what you need.
http://www.php.net/manual/en/class.ziparchive.php
Example from PHP.Net:
<?php
$zip = new ZipArchive;
if ($zip->open('test.zip') === TRUE) {
$zip->addFile('/path/to/index.txt', 'newname.txt');
$zip->close();
echo 'ok';
} else {
echo 'failed';
}
?>
After zipping it, you can output a mime-type header and output the file:
header('Content-type: application/zip');
readfile('test.zip');
this is the working example of making zip in php
$zip = new ZipArchive();
$zip_name = time().".zip"; // Zip name
$zip->open($zip_name, ZipArchive::CREATE);
foreach ($files as $file) {
echo $path = "uploadpdf/".$file;
if(file_exists($path)){
$zip->addFromString(basename($path), file_get_contents($path));
}
else{
echo"file does not exist";
}
}
$zip->close();

Categories