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?
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?
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.