While working on Zip file in your Laravel application, you might need to use PHP in-built class ZipArchive. When you use class in your controller file, you might get error "Class 'App\Http\Controllers\ZipArchive' not found"
.
To use ZipArchive class in PHP, you need to have installed and enabled zip extension which is which uses libzip. You can simply install zip extension with your enabled PHP version.
sudo apt-get install php7.4-zip
PHP8.0
sudo apt-get install php8.0-zip
And don't forget to restart apache server to implement changes.
sudo service apache2 restart
Now refresh the page and error should have gone. If you still get the error, make use you have use class above else Laravel will try to find class in your Controllers directory.
<?php
namespace App\Http\Controllers;
use ZipArchive;
/**
* Show the application homepage.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
...
$zip = new ZipArchive;
...
}
I hope this will help you.
Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]
How to Remove Duplicate Values from an Array in PHP
In this article, i will share with you h...How to create and download zip file using PHP
PHP provides simple method to create zip...How to Show Loading Spinner in jQuery
Use the ajaxStart() and ajaxStop() Metho...How to Create Directory if not exists in Laravel
In this Article, we will guide you how t...How to Get Query Parameters from URL route in Angular
Getting current URL and parameters is ba...