Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

rhand's avatar
Level 6

ZipArchive::close(): Failure to create temporary file: No such file or directory

I am having an issue downloading backups. We set up a new backup download option:

<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Models\Backup\Project as BackupProject;
use App\Models\Editor\Project;
use App\Services\ProjectService;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class BackupsController extends Controller
{
    public function download(BackupProject $backup)
    {
        $path = ProjectService::exportBackup($backup);
        \Storage::delete("projects/project-backup-{$backup->id}.zip");
        $zip = \Zip::create(storage_path('app/projects')."/project-backup-{$backup->id}.zip");

        // Add files
        $files = \Storage::files($path);
        foreach ($files as $file) {
            $zip->add(storage_path('app/'.$file), true);
        }

        // Add directories
        $zip->add(storage_path('app/').$path.'/uploads');

        $zip->close();

        return response()
                ->download(storage_path('app/projects')."/project-backup-{$backup->id}.zip", "{$backup->originalProject->name}-backup-{$backup->version}.zip");
    }
}

and on download we get an error 500 and in logs we see failure to create temporary backup.

ErrorExceptionGET /admin/backups/47785/download
ZipArchive::close(): Failure to create temporary file: No such file or directory
27 seconds ago
Jul 4th, 15:55:20 GMT+7
production
unhandled
ErrorException · ZipArchive::close(): Failure to create temporary file: No such file or directory
app/Http/Controllers/Admin/BackupsController.php:29 App\Http\Controllers\Admin\BackupsController::download
// Add directories
$zip->add(storage_path('app/').$path.'/uploads');
$zip->close();
return response()
->download(storage_path('app/projects')."/project-backup-{$backup->id}.zip", "{$backup->originalProject->name}-backup-{$backup->version}.zip");

This backup controller is a copy of another controller for the regular backups we also export to Digital Ocean Spaces. Those work without errors. Both use $zip->add(storage_path('app/').$path.'/uploads'); as storage path.

We do use symlinks to places like storage on our servers using PHP Deployer:

shared_dirs:
    - 'bootstrap/cache'
    - 'public/uploads'
    - 'public/published'
    - 'public/images'
    - 'public/downloads'
    - 'storage/framework/cache'
    - 'storage/framework/sessions'
    - 'storage/framework/views'
    - 'storage/logs'
    - 'storage/tls'
    - 'storage/app/downloads'
    - 'storage/app/modules'
    - 'storage/app/public'
  writable_dirs:
    - 'public/uploads'
    - 'public/published'
    - 'storage/framework/cache/data'
    - 'storage/logs'
    - 'storage/tls'
    - 'storage/app/downloads'
    - 'storage/app/modules'
    - 'storage/app/public'

But that has not caused issues creating zip files before so why now.

So now we wonder why this is happening? Do we need to add another disk? do we need to somehow indicate a better temporary path? And why? Why does it not work now?

0 likes
3 replies
rhand's avatar
Level 6

Hmm, yesterday things failed and now today the downloads do work. Trying to find the issue in the Nginx logs, but no luck yet. And Laravel logged error as shown earlier does not explain this change either. Why did it fail yesterday and not today?

rhand's avatar
Level 6

Just added another backup option and now the same issue for https://staging.site.com/admin/projects/502/export-publish as well:

ErrorException ·GET /admin/projects/501/export-publish
ZipArchive::close(): Failure to create temporary file: No such file or directory
Jul 5th 06:49:57 utc
S |

It will not download and browser tries export-publish.html instead. Our deployments run

task deploy:info
[staging] info deploying HEAD
task deploy:setup
task deploy:lock
task deploy:release
task deploy:update_code
task deploy:shared
task deploy:writable
task deploy:vendors
task artisan:storage:link
task artisan:view:cache
task artisan:config:cache
task artisan:optimize
task artisan:migrate
task artisan:queue:restart
task artisan:horizon:terminate
task deploy:symlink
task php-fpm:reload
[staging] warning Avoid reloading php-fpm [ï.at/avoid-php-fpm-reloading]
task deploy:unlock
task deploy:cleanup
task deploy:success

so routes should be fine or not?

rhand's avatar
rhand
OP
Best Answer
Level 6

Seems we need - 'storage/app/projects' added to writable and shareable directories as well. This to symlink this directory and allow writable access by PHP Deployer.

Please or to participate in this conversation.