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?
Problem solved. Made an obvious mistake: forgot to ''use ZipArchive'' in my Laravel controller
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With