zip在PHP中打开错误 [英] zipArchive open error in PHP

查看:239
本文介绍了zip在PHP中打开错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无法在PHP中创建zip归档文件,始终返回 ZIPARCHIVE :: ER_MULTIDISK

Cannot create zip archive in PHP, always returns ZIPARCHIVE::ER_MULTIDISK

$fileName=$_SERVER['DOCUMENT_ROOT'].'/temp/temp.zip';
$zip = new ZipArchive();
$err=$zip->open($fileName,ZipArchive::CREATE);
$zipFileFunctionsErrors = array(0=>'OK',
        ZIPARCHIVE::ER_MULTIDISK => 'Multi-disk zip archives not supported.',
        ...,
        ...
);
echo $zipFileFunctionsErrors[$err];
$zip->addFromString('empty.txt', '');
$zip->close();

输出

Multi-disk zip archives not supported

未创建zip文件

在本地机器代码上运行良好

on local machine code works good

推荐答案

我认为您的问题一定与php版本有关,听起来像是这样的: (来自php.net的评论):

I think that your issue has to be something with the php version, sounds like it's this: (from php.net comments):

如果zip_open失败,则某些较旧的PHP版本曾经返回false,而较新的版本则返回错误数(以整数形式),因此,代替此:

$zip = zip_open($zip_file);
if ($zip) {
  // consider zip file opened successfully
}

使用此:

$zip = zip_open($zip_file);
if (is_resource($zip)) {
  // consider zip file opened successfully
}

听起来像您从数组中获取第一个非数字索引,也许将"1"表示为"true",这就是为什么它在错误数组上显示元素"1"的原因

Sounds like you are getting the first non numeric index from the array, maybe '1' as 'true' and that's why it's displaying the element '1' on your errors array

这篇关于zip在PHP中打开错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆