简体   繁体   English

Laravel和ZipArchive-nvalid或未初始化的Zip对象

[英]Laravel and ZipArchive - nvalid or uninitialized Zip object

I need to create a zip using some file on my server. 我需要使用服务器上的某些文件来创建一个zip文件。
I used Zipper from here but it does not allow me to add a custom name while adding a file so I switched on ZipArchive . 我从这里开始使用Zipper ,但不允许我在添加文件时添加自定义名称,因此我打开了ZipArchive

Here the code: 这里的代码:

$zipper      = new \ZipArchive();

foreach ($tracks as $track) {
   $trackName = $track->name;
   $trackPath = $customUploads->getCustomTrackFilePath($track, true);
   $zipper->addFile($trackPath, $trackName);
}

$zipper->close();

Here the error: 这里的错误:

ErrorException in PlaylistController.php line 223: ZipArchive::addFile(): Invalid or uninitialized Zip object PlaylistController.php第223行中的ErrorException:ZipArchive :: addFile():无效或未初始化的Zip对象

I tried to add this control and when execute it I get the dd() message so looks like it is not able to create. 我试图添加此控件,并且在执行该控件时收到dd()消息,因此看起来无法创建。

if( $zipper->open($zipName) !== true ){
            dd('no');
        }

The strange thing is that with the library linked at the top the zip is created. 奇怪的是,通过顶部链接的库创建了zip。
Where is my error? 我的错误在哪里?

You are missing 2nd parameter flags of Zip::open function. 您缺少Zip::open函数的第二个参数flags Please check manual here http://php.net/manual/en/ziparchive.open.php 请在此处查看手册http://php.net/manual/zh/ziparchive.open.php

$zipper = $zip->open('test.zip', ZipArchive::CREATE);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ZipArchive :: getStatusString():无效或未初始化的Zip对象 - ZipArchive::getStatusString(): Invalid or uninitialized Zip object codeigniter phpexcel error ZipArchive::getFromName(): Invalid or uninitialized Zip object - codeigniter phpexcel error ZipArchive::getFromName(): Invalid or uninitialized Zip object PHP ZipArchive 在提取时给出无效或未初始化 Zip object 错误 - PHP ZipArchive gives Invalid or uninitialized Zip object error on extraction Laravel 5-PHP警告:ZipArchive :: extractTo():无效或单元化的Zip对象 - Laravel 5 - PHP Warning: ZipArchive::extractTo(): Invalid or unitialized Zip object ZipArchive::close() 无效或未初始化的 Zip 对象 - ZipArchive::close() Invalid or unitialized Zip object 使用 ZipArchive 在 Laravel 中创建 Zip 文件时出现未定义属性错误 - Undefind Property Error while creating Zip file in Laravel using ZipArchive 将CRON与ZIPArchive对象一起使用以创建zip文件-拒绝小名次 - using CRON with ZIPArchive object to create zip file— pemmisions denied PHPExcel警告:ZipArchive :: getFromName():无效或统一的Zip对象 - PHPExcel Warning: ZipArchive::getFromName(): Invalid or unitialized Zip object in zip with ZipArchive到PPTX错误 - zip with ZipArchive to PPTX errors 无法使用 ZipArchive 打开 zip - Unable to open zip with ZipArchive
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM