php页面内关闭警告,php – 关于ZipArchive关闭的警告

我试图在一个自动zip脚本中解决一些问题,这是我刚才写的一些图片,直到现在才有效.一切似乎都很好,直到$zip-> close();它给出了以下内容:

Warning: ZipArchive::close(): Read error: No such file or directory in on line 287

我阅读了文档和一些论坛,发现这可能发生在以下某种情况中:

>如果没有实际文件添加到zip,自PHP 5.6以来,这可能是一个可能的解释,因为我最近升级到PHP 5.6.然而:

>我在添加之前检查每个文件是否存在

>我试图在zip中添加一个虚拟的非空文本文件.将其添加到zip将返回true,文件上的file_exists()也是如此

>当我回显$zip-> numFiles并且它给出一个至少为1的数字(当zip没有文件时除了假人)

>如果需要写入zip的目录不存在或者没有正确的权限:这似乎不是这种情况,但只是为了确定,我写了一个文本文件到同一个文件夹在同一个脚本中没有问题

>如果写入临时目录时出现问题.检查这个有点难,但我在同一系统中有一个上传脚本,我确保没有磁盘空间问题等.

这是相关的代码.一些变量是事先定义的.请注意,我将每个问题写入我的日志,并且此脚本不会生成任何条目!

$zip_file = 'Project'.$project_id.'.zip';

$zip = new ZipArchive;

if ($zip_result = $zip->open($zip_path.'/'.$zip_file, ZIPARCHIVE::CREATE) !== true) {

echo 'Error creating zip for project: '.$project_id.'. Error code: '.$zip_result;

help::debugLog('Error creating zip for project: '.$project_id.'. Error code: '.$zip_result);

return false;

}

$file_list = array();

foreach ($item_thumbs as $item)

{

$full_thumb_path = $thumb_dir.'/'.$item['thumb'];

if (file_exists($full_thumb_path) and $item['thumb'])

{

$file_added = $zip->addFile($full_thumb_path, basename($item['thumb']));

if (!$file_added)

help::debugLog('Failed to add item thumb to project zip. Project: '.$project_id.', file name: '.$item['thumb']);

else

$file_list[] = $item['thumb'];

}

elseif ($item['thumb']) /* If thumb indicated in DB doesn't exist in file system */

help::debugLog('Item thumb file '.$item['thumb'].' from item: '.$item['id'].' is missing from its indended location: '.$full_thumb_path);

}

/* Added 2016-05-18 -- creates dummy file for the zip listing its contents, important in case zip is empty */

$file_list_path = $zip_path.'/file_list.txt';

if (!($file_list_file = fopen($file_list_path, 'w+')))

help::debugLog('Failed to create list file (intended for zip) for project: '.$project_id);

fwrite($file_list_file, "File list:\n");

fwrite($file_list_file, implode("\n", $file_list));

if (file_exists($file_list_path))

{

fclose($file_list_file);

if (!$zip->addFile($file_list_path))

help::debugLog('Failed to add list file to project zip for project: '.$project_id);

unlink($file_list_path);

}

else

help::debugLog('Failed to create list file (intended for zip) for project: '.$project_id);

$zip->close(); // line 287

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值