{"id":929,"date":"2024-08-02T16:11:36","date_gmt":"2024-08-02T16:11:36","guid":{"rendered":"https:\/\/www.cmsgalaxy.com\/blog\/?p=929"},"modified":"2024-08-02T16:11:36","modified_gmt":"2024-08-02T16:11:36","slug":"create-zip-file-and-download-in-laravel-9","status":"publish","type":"post","link":"https:\/\/www.cmsgalaxy.com\/blog\/create-zip-file-and-download-in-laravel-9\/","title":{"rendered":"Create Zip File and Download in Laravel 9"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The reaction to laravel 9 zip download is the main topic of this tutorial. This tutorial covers how to produce a zip file in Laravel 9 in depth. You\u2019ve come to the right place if you want to see an example of how to produce a zip file and download it using Laravel 9. Laravel 9 create zip from folder, as seen.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Large volumes of data are frequently organized and compressed using the zip file format. It is a well-liked technique for lowering the size of huge files or folders for better sharing and storage. Zip files reduce the size of several files or folders while preserving their structure and contents by compressing them into a single archive. As a result, they are simpler to download or share online and take up less space when being transferred or stored.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this article, I\u2019ll demonstrate how to create a zip file in Laravel using the two methods below. one employing the stechstudio\/laravel-zipstream package and the other ZipArchive. We\u2019ll just make a folder called \u201cmyFiles\u201d and a zip file from it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Let\u2019s examine each of the two situations separately.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"> public function __invoke()<br>    {<br>        $zip = new ZipArchive;<br>    <br>        $fileName = 'myNewFile.zip';<br>     <br>        if ($zip->open(public_path($fileName), ZipArchive::CREATE) === TRUE)<br>        {<br>            $files = File::files(public_path('myFiles'));<br>     <br>            foreach ($files as $key => $value) {<br>                $relativeNameInZipFile = basename($value);<br>                $zip->addFile($value, $relativeNameInZipFile);<br>            }<br>               <br>            $zip->close();<br>        }<br>      <br>        return response()->download(public_path($fileName));<br>    }<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The reaction to laravel 9 zip download is the main topic of this tutorial. This tutorial covers how to produce<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-929","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/posts\/929","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/comments?post=929"}],"version-history":[{"count":1,"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/posts\/929\/revisions"}],"predecessor-version":[{"id":930,"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/posts\/929\/revisions\/930"}],"wp:attachment":[{"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/media?parent=929"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/categories?post=929"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/tags?post=929"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}