Class 'frontend\controllers\ZipArchive' not found

i have an error when try to make file zip and download it. the class zip archive not found. but when i try it with simple php code it’s work. i use xampp 7 and the zip class was include in php when instal xampp. but in yii2 it’s error.

7218

error1.PNG

this my class download in my controller


public function actionDownload()

    {

        $zipnam="QR Code ".Yii::$app->user->identity->username; 

        $dir=realpath(Yii::$app->basePath.'/web/assets/QR/temp/').'/'.Yii::$app->user->identity->username;

        $file=scandir($dir);

        $del=TRUE;

        print_r($file);


        $filestozip = $file; // FILES ARRAY TO ZIP

        $dir = trim($dir); // DIR NAME TO MOVE THE ZIPPED FILES

        $zipnam = trim($zipnam);


        $zip = new ZipArchive();

        $files = $filestozip;

        $zip_name = $zipnam.".zip";

        $fizip = $dir.$zip_name;

        if($zip->open($fizip, ZipArchive::CREATE) === TRUE) {

            foreach ($files as $fl) {

              if(file_exists($fl)){

                $zip->addFromString(basename($fl),  file_get_contents($fl));

                // $zip= $zip+$fl;

                if($del === TRUE) {

                    unlink($fl);

                }

              }

            }

            $zip->close();

            return TRUE;

        } else { $zip->close(); return FALSE;}

    }

is there something i forgot to include?

Either do it like:


$zip = new \ZipArchive();

or place use in class file:


use ZipArchive;

thank you so much… :D