0

I've created a simple programe that put photos into ZipArchive. All is working till I try to compress more than a couple photos (about 60). And after than I have something like that on a screen:

https://i.stack.imgur.com/DtgHG.png

I've changed max_execution_time to 1200 and memory_limit to 256M in php.ini.

Server is on Nginx 1.18 with PHP7.4 and Ubuntu 20.4. All is working on Laravel 8.

Any ideas?

This is my ZipController

public function downloadZip(Request $req){   

    $id = $req->input('id');

    $sessions = DB::table('sessions')->where('id', $id)->get();
    $photos = DB::table('sessions_files')->where('session_id', $id)->get();

    $zip = new ZipArchive;

    $path = 'images/sessions/'.$id;

    $fileName = 'Sesja-numer-'.$id.'.zip';

    if ($zip->open($fileName, ZipArchive::CREATE) === TRUE)
    {
        $numerek = 1;
        foreach ($photos as $photo) {
            echo $photo->file;
            $addFile = $path.'/'.$photo->file;
            $fileNewName = 'Zdjecie-'.$numerek.'.jpg';
            $zip->addFile($addFile, $fileNewName);
            $numerek++;
        }
        ob_end_clean();
        $zip->close();            
    }
    
    return response()->download($fileName)->deleteFileAfterSend();
    return redirect('/dashboard/sessions/'.$id);

}
  • 1
    That looks like what happens when you open a zip file in a text editor. Or display a zip file on screen. – aynber Dec 29 '21 at 18:30
  • Can you share the relevant code? – Maik Lowrey Dec 29 '21 at 18:34
  • 3
    Scroll all the way to the bottom and see if there's an error message (make sure visible errors are enabled) or see the error logs. Always check for errors first. – KIKO Software Dec 29 '21 at 18:52
  • Please provide enough code so others can better understand or reproduce the problem. – Community Jan 07 '22 at 02:43
  • I have had that before, it happens when you add a file to the ziparchive, and that file doesn't exist or is not readable due to file permissions. Best to check file_exists() before adding it to the archive. The zip archive doesn't hit the error until you close, and it try's to read all the files at that point – bumperbox Feb 21 '22 at 21:47

0 Answers0