samedi 29 juin 2019

php ZipArchive::close() not working on webserver

I am building a folder with files in it. At the end, I want to Zip this folder. On my local machine using homestead, everything works correctly. However, on my webserver I am getting the error

ZipArchive::close(): Can't remove file: No such file or directory

Why? The folder is filled with all files...

My Code

$zip_file = storage_path('app\\takeouts\\takeout_' . $this->dataExports->uuid . '.zip');
        $this->zip = new \ZipArchive();
        $this->zip->open($zip_file, \ZipArchive::CREATE | \ZipArchive::OVERWRITE);
        $this->addAllFilesToZipArchive($this->folder_name);
        $this->zip->close();

        Storage::deleteDirectory($this->folder_name);


private function addAllFilesToZipArchive($dir)
    {
        $dirs = Storage::directories($dir);
        $files = Storage::files($dir);
        foreach ($files as $file)
        {
            if(Storage::exists(storage_path("app\\" . $file))) {
                $this->zip->addFile(storage_path("app\\" . $file), str_replace($this->folder_name,"","/" . $file));
            }
        }
        foreach ($dirs as $dir2) {
            $this->addAllFilesToZipArchive($dir2);
        }
    }



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2IVTGr4
via IFTTT

Aucun commentaire:

Enregistrer un commentaire