PHP ZipArchive 状态值的含义是什么?
我正开始尝试编写一些 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();
?>
输出 =
文件数:2 状态:11
我在“uploads”文件夹中没有看到任何 zip 文件
我尝试的第二段代码(我不会在此处发布代码) - 我传递真实文件并返回
zip 存档包含 2 个状态为 0 的文件
状态消息是什么。我通过查看 phpinfo(); 的输出来检查是否安装了正确的库。在 ZIP 标题下我看到 -
启用 Zip
扩展版本 $Id: php_zip.c,v 1.1.2.43 2008/01/18 00:51:38 pajoye Exp $
压缩版本 1.8.11
Libzip 版本 0.8.0 兼容
我已经使用我正在执行的代码检查了 PHP 文件的权限,并将它们设置为 777,就像我尝试将 ziparchive 添加到的文件夹一样。我知道这不应该保留在 777。
有什么想法为什么我看不到 zip 文件吗?状态值是什么意思?有没有关于使用 PHP 在 Amazon S3 存储桶上压缩文件的好教程?或者提供此功能的好实用程序?
干杯
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在这里找到它:
http://www.php.net/manual/en/zip.constants.php
错误 11 是“无法打开文件”
You can find it here:
http://www.php.net/manual/en/zip.constants.php
Error 11 is "Can't open file"
就我而言,我在打开 zip 文件进行阅读时收到错误代码 11。路径和权限都OK。 我刚刚将目录分隔符从反斜杠 (\) 更改为正斜杠 (/),并且它起作用了。奇怪的是,正斜杠 (/) 路径在 Linux 中,而我在 Windows Server 2003 中工作。
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.