Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP ZipArchive Not Working in Laravel

Tags:

php

PHP ZipArchive is working perfectly if I run it in raw php, but getting a "class not found" error when I try to run it in my Laravel project:

FatalErrorException in WidgetController.php line 40: Class 'App\Http\Controllers\ZipArchive' not found

Here's the function I have in my laravel controller:

public function installHello()
{
    $file_path = base_path("resources/assets/packages/helloworld.zip");

    $zip = new ZipArchive;
    if ($zip->open($file_path) === TRUE) {
        $zip->extractTo(base_path('packages/tkabir/'));
        $zip->close();
        return redirect()->back();
        //echo 'ok';
    } else {
        echo 'failed';
    }
}

And here's the sample I tried in an index.php file:

<?php
$zip = new ZipArchive;
if ($zip->open('E:/xampp/htdocs/ziptest/helloworld.zip') === TRUE) {
    $zip->extractTo('E:/xampp/htdocs/ziptest/');
    $zip->close();
    echo 'ok';
} else {
    echo 'failed';
}
?>

Any idea why it wouldn't work in laravel?

like image 257
BangularTK Avatar asked Nov 30 '22 15:11

BangularTK


1 Answers

Problem solved. Made an obvious mistake: forgot to ''use ZipArchive'' in my Laravel controller

like image 102
BangularTK Avatar answered Dec 06 '22 15:12

BangularTK