[英]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.