我刚开始尝试编写一些 PHP 代码以在 EC2 服务器上的 Linux 机器上运行,它将从我的 S3 存储桶中读取文件,压缩它们,然后将 zip 文件写回存储桶。
即使从 EC2 实例的本地磁盘上的一些图像创建简单的 zip 存档,我也立即遇到了问题,我正在使用脚本来测试在线 PHP 手册中的想法,并且还尝试了一个David Walsh 的脚本 - http://davidwalsh.name/create-zip-php看起来会很棒。既没有产生实际的 zip 文件,也没有给我不同的状态结果 -
php 手册中的第一个片段(我向其中添加变量 $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();
?>
输出=
numfiles: 2 status:11
我在“上传”文件夹中没有看到任何 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 存储桶的好教程?还是提供此功能的好工具?
干杯
最佳答案
你可以在这里找到它: http://www.php.net/manual/en/zip.constants.php
错误 11 是“无法打开文件”
关于PHP ZipArchive 状态值是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3389416/