7

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

4

2 回答 2

14

你可以在这里找到它: http ://www.php.net/manual/en/zip.constants.php

错误 11 是“无法打开文件”

于 2010-09-17T08:00:53.690 回答
1

在我的情况下,我在打开 zip 文件进行阅读时收到错误代码 11。路径和权限都可以。我刚刚将 DIRECTORY SEPARATOR 从反斜杠 (\) 更改为正斜杠 (/) 并且它起作用了。奇怪的是,正斜杠 (/) 路径位于 Linux 中,而我在 Windows Server 2003 中工作。

于 2013-04-14T12:33:52.260 回答