我正在开始尝试编写一些
PHP代码,以便在EC2服务器上的Linux机器上运行,该服务器将从我的S3存储桶读取文件,压缩它们然后将zip文件写回存储桶.
即使从EC2实例的本地磁盘上的一些图像创建一个简单的zip存档,我也立刻遇到了问题,我正在使用脚本在线测试PHP手册中的想法,并且还尝试了David的脚本Walsh – http://davidwalsh.name/create-zip-php看起来很棒.既没有产生实际的zip文件,也没有给我不同的状态结果 –
php手册中的第一个片段(我添加变量$thisdir) –
$zip = new ZipArchive();
$filename = "test112.zip";
$thisdir = "/uploads/";
if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) {
exit("cannot open \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();
?>
输出=
numfiles: 2 status:11
我在’uploads’文件夹中看不到任何zip文件
我尝试的第二段代码(我不会在这里发布代码) – 我传递真实文件然后返回
The zip archive contains 2 files with a status of 0
有什么状态信息.我通过查看phpinfo()的输出检查是否安装了正确的库;在ZIP标题下,我看到 –
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
我已经使用我正在执行的代码检查了文件PHP文件的权限,并将它们设置为777,因为我正在尝试添加ziparchive的文件夹.我知道这不应该留在777.
任何想法为什么我看不到一个zip文件?状态值是什么意思?是否有一个很好的教程,使用PHP来压缩Amazon S3存储桶上的文件?或者是提供此功能的好工具?
干杯