zipArchive open error in PHP

半城伤御伤魂 提交于 2019-11-28 11:24:42

问题


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();

Outputs

Multi-disk zip archives not supported

zip file didn't created

on local machine code works good


回答1:


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

Some older PHP versions used to return false if zip_open failed, and newer versions return the number of error (as integer), so instead of this:

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

use this:

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

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




回答2:


First, check if you can create files with php on server side. There may be an identity problem. php may operate on i.e: apache id and your id is yourFtpId..

Then check if zip library is supported with php on the server, phpinfo can show that.

Then check if your server configuration allows zip commands from php.

When these diagnostics are over, if you find a problem with these, you should address the server admin to solve them.



来源:https://stackoverflow.com/questions/15381142/ziparchive-open-error-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!