Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP ZipArchive what do status values mean?

Tags:

php

ziparchive

I am right at the start of trying to write some PHP code to run on a Linux box on an EC2 server that will read files from my S3 bucket, zip them then write the zip file back to the bucket.

I have instantly run in to problems with even creating a simple zip archive from some images on the local disk of the EC2 instance, I am using a script to test out the idea from the PHP manual online and also have tried out a script from David Walsh - http://davidwalsh.name/create-zip-php which looks like it will be great. Neither result in an actual zip file and both give me different status results -

the first snippet from the php manual (to which i add the variable $thisdir)-

<?php
$zip = new ZipArchive();
$filename = "test112.zip";
$thisdir = "/uploads/";
if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) {
    exit("cannot open <$filename>\n");
}    
$zip->addFromString("testfilephp.txt" . time(), "#1 This is a test string added as testfilephp.txt.\n");
$zip->addFromString("testfilephp2.txt" . time(), "#2 This is a test string added as testfilephp2.txt.\n");
$zip->addFile($thisdir . "/too.php","/testfromfile.php");
echo "numfiles: " . $zip->numFiles . "\n";
echo "status:" . $zip->status . "\n";
$zip->close();
?>

output =

numfiles: 2 status:11

I dont see any zip file in my 'uploads' folder

The second bit of code i try ( i wont post the code here) - I pass real files and it returns

The zip archive contains 2 files with a status of 0

What are the status messages. I have checked to see if I have the correct libraries installed by looking at the output of phpinfo(); and under the ZIP heading I see -

Zip enabled
Extension Version $Id: php_zip.c,v 1.1.2.43 2008/01/18 00:51:38 pajoye Exp $
Zip version 1.8.11
Libzip version 0.8.0-compatible

I have checked the permissions of the files PHP files with the code I am executing and they are set to 777 as is the folder I am trying to add the ziparchive to. I know that this should not remain at 777.

any ideas why I cannot see a zip file? what do the status values mean? Is there a good tutorial out there for using PHP to zip files on an Amazon S3 bucket? or a good utility to provide this functionality?

cheers

like image 551
undefined Avatar asked Aug 02 '10 15:08

undefined


2 Answers

You can find it here: http://www.php.net/manual/en/zip.constants.php

Error 11 is "Can't open file"

like image 197
Logician Avatar answered Nov 07 '22 21:11

Logician


In my case i got error code 11 while opening a zip file for reading. The path and permissions are OK. I just changed the DIRECTORY SEPARATOR from back slash (\) to forward slash (/) and it worked. The strange thing is that forward slash (/) paths are in Linux where as I am working in windows server 2003.

like image 23
asim-ishaq Avatar answered Nov 07 '22 22:11

asim-ishaq