zanysoft / laravel-zip Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
Hi, could you please add support for newest version of Laravel (11)?
Hi I have problem with overwrite file in zip already exists any help?
I checked flow need to delete folder in zip before add exact this folder to zip again and it's worked but no have ways for delete folder in zip from code!!
Also I try not delete anything and just open and add exists path to zip but content not overwrite!!
Can i do $zip->extract('/path/to/uncompressed/files', 'myfolder'); ?
...
Hi, I have recently upgraded the package and now I am getting following error, I think $zip_file must be type of object not string
Error: Cannot assign Illuminate\Foundation\Application to property ZanySoft\Zip\Zip::$zip_file of type ?string
Code:
$zipFiles = [ '/var/www/cml/public/data/temp/new/01.pdf', '/var/www/cml/public/data/temp/new/02.pdf', '/var/www/cml/public/data/temp/new/02.pdf', ]; $zip = Zip::create('/var/www/cml/public/data/temp/new.zip'); $zip->add($zipFiles); $zip->close();
Screenshot:
Unparenthesized
a ? b : c ? d : eis deprecated. Use either
(a ? b : c) ? d : eor
a ? b : (c ? d : e){"exception":"[object] (ErrorException(code: 0): Unparenthesized
a ? b : c ? d : eis deprecated. Use either
(a ? b : c) ? d : eor
a ? b : (c ? d : e) at /home/vagrant/tyrepress-api/vendor/zanysoft/laravel-zip/src/Zip.php:405)
Updated Laravel to 6.6 and PHP7.4
See stacktrace below
[stacktrace]
#0 /home/vagrant/api/vendor/composer/ClassLoader.php(444): Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleError()
#1 /home/vagrant/api/vendor/composer/ClassLoader.php(444): include()
#2 /home/vagrant/api/vendor/composer/ClassLoader.php(322): Composer\\Autoload\\includeFile()
#3 [internal function]: Composer\\Autoload\\ClassLoader->loadClass()
#4 /home/vagrant/api/vendor/zanysoft/laravel-zip/src/ZipServiceProvider.php(30): spl_autoload_call()
#5 /home/vagrant/api/vendor/laravel/framework/src/Illuminate/Container/Container.php(799): ZanySoft\\Zip\\ZipServiceProvider->ZanySoft\\Zip\\{closure}()
#6 /home/vagrant/api/vendor/laravel/framework/src/Illuminate/Container/Container.php(681): Illuminate\\Container\\Container->build()
#7 /home/vagrant/api/vendor/laravel/framework/src/Illuminate/Container/Container.php(629): Illuminate\\Container\\Container->resolve()
#8 /home/vagrant/api/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(768): Illuminate\\Container\\Container->make()
#9 /home/vagrant/api/vendor/laravel/framework/src/Illuminate/Container/Container.php(1245): Illuminate\\Foundation\\Application->make()
#10 /home/vagrant/api/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(182): Illuminate\\Container\\Container->offsetGet()
#11 /home/vagrant/api/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(150): Illuminate\\Support\\Facades\\Facade::resolveFacadeInstance()
#12 /home/vagrant/api/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(239): Illuminate\\Support\\Facades\\Facade::getFacadeRoot()
#13 /home/vagrant/api/app/Repositories/FeedRepository.php(1949): Illuminate\\Support\\Facades\\Facade::__callStatic()
#14 /home/vagrant/api/app/Jobs/ProcessReviews.php(36): App\\Repositories\\FeedRepository->importFromUpload()
#15 [internal function]: App\\Jobs\\ProcessReviews->handle()
#16 /home/vagrant/api/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(32): call_user_func_array()
#17 /home/vagrant/api/vendor/laravel/framework/src/Illuminate/Container/Util.php(34): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#18 /home/vagrant/api/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(90): Illuminate\\Container\\Util::unwrapIfClosure()
#19 /home/vagrant/api/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(34): Illuminate\\Container\\BoundMethod::callBoundMethod()
#20 /home/vagrant/api/vendor/laravel/framework/src/Illuminate/Container/Container.php(590): Illuminate\\Container\\BoundMethod::call()
#21 /home/vagrant/api/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(94): Illuminate\\Container\\Container->call()
#22 /home/vagrant/api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(130): Illuminate\\Bus\\Dispatcher->Illuminate\\Bus\\{closure}()
#23 /home/vagrant/api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(105): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#24 /home/vagrant/api/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(98): Illuminate\\Pipeline\\Pipeline->then()
#25 /home/vagrant/api/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(83): Illuminate\\Bus\\Dispatcher->dispatchNow()
#26 /home/vagrant/api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(130): Illuminate\\Queue\\CallQueuedHandler->Illuminate\\Queue\\{closure}()
#27 /home/vagrant/api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(105): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#28 /home/vagrant/api/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(85): Illuminate\\Pipeline\\Pipeline->then()
#29 /home/vagrant/api/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(59): Illuminate\\Queue\\CallQueuedHandler->dispatchThroughMiddleware()
#30 /home/vagrant/api/vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php(88): Illuminate\\Queue\\CallQueuedHandler->call()
#31 /home/vagrant/api/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(348): Illuminate\\Queue\\Jobs\\Job->fire()
#32 /home/vagrant/api/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(294): Illuminate\\Queue\\Worker->process()
#33 /home/vagrant/api/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(247): Illuminate\\Queue\\Worker->runJob()
#34 /home/vagrant/api/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(112): Illuminate\\Queue\\Worker->runNextJob()
#35 /home/vagrant/api/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(96): Illuminate\\Queue\\Console\\WorkCommand->runWorker()
#36 [internal function]: Illuminate\\Queue\\Console\\WorkCommand->handle()
#37 /home/vagrant/api/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(32): call_user_func_array()
#38 /home/vagrant/api/vendor/laravel/framework/src/Illuminate/Container/Util.php(34): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#39 /home/vagrant/api/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(90): Illuminate\\Container\\Util::unwrapIfClosure()
#40 /home/vagrant/api/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(34): Illuminate\\Container\\BoundMethod::callBoundMethod()
#41 /home/vagrant/api/vendor/laravel/framework/src/Illuminate/Container/Container.php(590): Illuminate\\Container\\BoundMethod::call()
#42 /home/vagrant/api/vendor/laravel/framework/src/Illuminate/Console/Command.php(202): Illuminate\\Container\\Container->call()
#43 /home/vagrant/api/vendor/symfony/console/Command/Command.php(255): Illuminate\\Console\\Command->execute()
#44 /home/vagrant/api/vendor/laravel/framework/src/Illuminate/Console/Command.php(189): Symfony\\Component\\Console\\Command\\Command->run()
#45 /home/vagrant/api/vendor/symfony/console/Application.php(1011): Illuminate\\Console\\Command->run()
#46 /home/vagrant/api/vendor/symfony/console/Application.php(272): Symfony\\Component\\Console\\Application->doRunCommand()
#47 /home/vagrant/api/vendor/symfony/console/Application.php(148): Symfony\\Component\\Console\\Application->doRun()
#48 /home/vagrant/api/vendor/laravel/framework/src/Illuminate/Console/Application.php(90): Symfony\\Component\\Console\\Application->run()
#49 /home/vagrant/api/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(131): Illuminate\\Console\\Application->run()
#50 /home/vagrant/api/artisan(37): Illuminate\\Foundation\\Console\\Kernel->handle()
#51 {main}
"}
use ZanySoft\Zip\Zip;
$zip = Zip::create('files/test.zip');
Am I missing something? The Readme tells me to call a static function, but there is none.
Would be nice if you released the latest changes from commit 5debb95 ;)
I want to upload monthly newsletter on my website with zip file, Upload and extract properly but when opening it HTML open properly but the image path not found properly example I upload January month newsletter but the image path show http://my website/images/newsletter/photo.jpg but my file is in http://my website/images/newsletter/january/photo.jpg how can I solve
NB: HTML file and image file are in the same folder.
Hey,
Laravel 5.5 introduce a nice new way to add Facades and Service Provider.
You should add following to the composer.json section:
"extra": {
"laravel": {
"providers": [
"ZanySoft\\Zip\\ZipServiceProvider"
],
"aliases": {
"Zip": "ZanySoft\\Zip\\ZipFacade"
}
}
},
Then Laravel will automatically register this service providers and facades when it is installed.
Unparenthesized a ? b : c ? d : e
is not supported. Use either (a ? b : c) ? d : e
or a ? b : (c ? d : e)
{"exception":"[object] (Symfony\Component\ErrorHandler\Error\FatalError(code: 0): Unparenthesized a ? b : c ? d : e
is not supported. Use either (a ? b : c) ? d : e
or a ? b : (c ? d : e)
at /var/www/ksa/vendor/zanysoft/laravel-zip/src/Zip.php:405)
when i run php artisan serve
ErrorException : Unparenthesized a ? b : c ? d : e
is deprecated. Use either (a ? b : c) ? d : e
or a ? b : (c ? d : e)
at C:\Users\Atif\Desktop\Multi Restaurants Laravel App\vendor\themsaid\laravel-langman\src\Commands\FindCommand.php:113
109| $original = [];
110|
111| foreach ($allLanguages as $languageKey) {
112| $original[$languageKey] =
114| ? $values[$languageKey]
115| : isset($filesContent[$fileName][$languageKey][$key]) ? $filesContent[$fileName][$languageKey][$key] : '';
116| }
117|
Exception trace:
1 Illuminate\Foundation\Bootstrap\HandleExceptions::handleError("Unparenthesized a ? b : c ? d : e
is deprecated. Use either (a ? b : c) ? d : e
or `a ? b :staurants Laravel App\vendor\composer/../themsaid/laravel-langman/src/Commands/FindCommand.php"])
C:\Users\Atif\Desktop\Multi Restaurants Laravel App\vendor\composer\ClassLoader.php:444
2 include()
C:\Users\Atif\Desktop\Multi Restaurants Laravel App\vendor\composer\ClassLoader.php:444
Please use the argument -v to see more details.
PS C:\Users\Atif\Desktop\Multi Restaurants Laravel App> -v
PS C:\Users\Atif\Desktop\Multi Restaurants Laravel App> php artisan migrate
ErrorException : Unparenthesized a ? b : c ? d : e
is deprecated. Use either (a ? b : c) ? d : e
or a ? b : (c ? d : e)
at C:\Users\Atif\Desktop\Multi Restaurants Laravel App\vendor\themsaid\laravel-langman\src\Commands\FindCommand.php:113
109| $original = [];
110|
111| foreach ($allLanguages as $languageKey) {
112| $original[$languageKey] =
113| isset($values[$languageKey])
114| ? $values[$languageKey]
115| : isset($filesContent[$fileName][$languageKey][$key]) ? $filesContent[$fileName][$languageKey][$key] : '';
116| }
117|
Exception trace:
1 Illuminate\Foundation\Bootstrap\HandleExceptions::handleError("Unparenthesized a ? b : c ? d : e
is deprecated. Use either (a ? b : c) ? d : e
or a ? b : (c ? d : e)
", "C:\Users\Atif\Desktop\Multi Restaurants Laravel App\vendor\themsaid\laravel-langman\src\Commands\FindCommand.php", ["C:\Users\Atif\Desktop\Multi Restaurants Laravel App\vendor\composer/../themsaid/laravel-langman/src/Commands/FindCommand.php"])
C:\Users\Atif\Desktop\Multi Restaurants Laravel App\vendor\composer\ClassLoader.php:444
2 include()
C:\Users\Atif\Desktop\Multi Restaurants Laravel App\vendor\composer\ClassLoader.php:444
Please use the argument -v to see more details.
Hello!
Is there any way to do an archive on the fly without using the file system?
As I am trying to create a zip directory in digital ocean space with multiple subfolders and I want to provide it for users to download. But I am unable to do that.
How save to specific directory created file zip
maybe like:
$zip=Zip::create('package.zip');
$zip->add(['file 1','file 2']);
$zip->SaveTo($path);
I keep getting this "Read error", no matter the path I use;
$zippedFile = Storage::disk('vr')->url($path);
$storage = public_path('storage/vr/'.$fileName);
$zip = Zip::open($path);
Hello, I'm trying to use this library, but I'm getting the error "zip archive inconsistent" when I'm trying to open every file zip.
No matter how I create a zip file.
I've always get development.ERROR: Zip archive inconsistent
Am I missing something?
This is the file zip we are trying to use.
Thanks!
micro-import.zip
\m
@zanysoft, congrats for this great PHP package, the syntax is very expressive!
Can you clarify the license for the code by including a LICENSE.md file in your repository?
I can't really see an option to add files to an existing .zip file. Is it possible?
Hi,
Does it support addFromString, if not, could you add this method?!
thank you in advance.
This package hasn't received a release in several years and is incompatible with php 7.4 due to a minor issue.
Please mark the package as abandoned to dissuade people from using it in the future.
Hi, How can I count entries of zip file using laravel-zip?
I tried to do it with this code, but I didn't know how to download it after I created the zip file.
here's my code in controller:
//Convert data into pdf then save it to local storage
$apply = Form::all();
view()->share('apply', $apply);
$pdf = PDF::loadView('admin.pdf-apply')->setPaper('a4', 'landscape');
Storage::put('public/pdf/data_applicant.pdf', $pdf->output());
//Create a zip from it and download it
$zip = Zip::create('public/storage/file.zip');
Storage::put('public/pdf/file.zip', $zip->add('public/storage/pdf/data_applicant.pdf'));
$zip->close();
return response()->download($zip);
On the local machine, everything works as it should, but on the production on some archives an error appears Not a zip archive {"exception": "[object] (Exception (code: 0): Not a zip archive at /var/www ... vendor / zanysoft / laravel-zip / src / Zip.php: 631)
I have 3 plans and that has feature with Quota, but the third plan offers unlimited usage of that feature. I still want to make the feature consumable
and with quota
. Do you have any solution for this scenario?
Hello. Is there's a way that I can store the extracted files to s3 instead in my public folder?
How rename file / directory when add file/directory
like $zip->add('file_1.doc' => 'renamefile_1.doc');
Hi,
I'm Receiving the Following Error after Updating the Laravel to Version 9 and PHP 8.1
PHP Fatal error: Unparenthesized a ? b : c ? d : e
is not supported. Use either (a ? b : c) ? d : e
or a ? b : (c ? d : e)
in C:--------\vendor\zanysoft\laravel-zip\src\Zip.php on line 405
Symfony\Component\ErrorHandler\Error\FatalError
Unparenthesized a ? b : c ? d : e
is not supported. Use either (a ? b : c) ? d : e
or a ? b : (c ? d : e)
at C:-----------\vendor\zanysoft\laravel-zip\src\Zip.php:405
401 if (!is_array($files) && !is_string($files) && !is_null($files)) {
402 throw new Exception('Invalid extractable files');
403 }
404
405 $files = is_array($files) ? $files : is_string($files) ? [$files]: $files;
406
407 if (@sizeof($files) != 0 ) {
408 $file_matrix = $files;
409 } else {
1 C:-------\vendor\filp\whoops\src\Whoops\Run.php:486
Whoops\Run::handleError()
Please help in rectifying
Thanks
Hello Zippers.
I try use this library in my project but when I try make a IDE Helpers, I get error.
> if [ $COMPOSER_DEV_MODE -eq 1 ]; then php artisan ide-helper:generate; fi
TypeError
Cannot assign Illuminate\Foundation\Application to property ZanySoft\Zip\Zip::$zip_file of type ?string
at vendor/zanysoft/laravel-zip/src/Zip.php:114
110▕ if (empty($zip_file)) {
111▕ throw new \Exception(self::getStatus(ZipArchive::ER_NOENT));
112▕ }
113▕
➜ 114▕ $this->zip_file = $zip_file;
115▕ }
116▕
117▕ /**
118▕ * Open a zip archive
+28 vendor frames
29 artisan:37
Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
How is possible fix this problem.
Thanks very much for this library
Yoinier.
Composer State : ^1.0
**$zip->extract('/path/to/uncompressed/files', array('file1','file2'))**
Does not seem to work on the current dev system (win7,laragon ->php.7.1.7)
$zip->listFiles >[toCollection]->filter (remove anything that is not srt) -> toArray:
$test =[
test with spaces .srt,
someotherfiler.srt,
Another.srt,
]
$zip->extract('/path/to/uncompressed/files', $test);
Returns no errors , but also no files extracted.
if I try to extract the zip with a single filename it works.
$zip->extract('/path/to/uncompressed/files', 'test with spaces .srt');
Thank you for this very nice extension , when i got some time I will look into the problem myself and see if we can come up for a solution if you don't know what the cause is.
Cheers,
Paolo
Laravel Zip is really nice! Thank you. Is there a chance you could add support to specify a subfolder to the "add" method, so that files will appear in subfolders when extracting? Thank you very much in advance.
$zip->add($file,$subdir);
I am trying to create a password protected zip file, eerything works fine except password. My code is as follows:
$zip = \ZanySoft\Zip\Zip::create(storage_path().'/app/uploads/bdo/file.zip');
$zip->add(storage_path().'/app/uploads/bdo/abc.txt');
$password = 'top-secret';
if (!$zip->setPassword($password)) {
throw new RuntimeException('Set password failed');
}
$zip->close();
Please help.
In PHP 8.1, we can see that one of your methods (at least one) has a deprecation warning:
PHP Deprecated: ZipArchive::open(): Passing null to parameter #2 ($flags) of type int is deprecated in /var/www/vendor/zanysoft/laravel-zip/src/Zip.php on line 636
This happens when I just Zip::open($filename)
The reason for this seems to be that your DocBlock defines @param int $flags ZIP status code
but you are calling the method with null
for this field. The DocBlock needs to be updated to allow int
to be null, so @param ?int $flags ZIP status code
Hi, i was trying to use this class and I need to extend it to add some features related to my business logic.
I see that inside ZanySoft\Zip\Zip
class, a lot of properties and methods are setted to private
.
This behaviour prevents me from extending class.
Is it possible to change all private
to protected
?
If necessary, I can submit a PR with these changes
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.