So I've been trying to find a solution for this and I think it's got to do with the way I am creating the zip on the storage.
Controller:
$disk = Storage::disk('s3');
if($disk->exists('storage/mail_attachments/'.$this->zip_file)) {
$disk->delete('storage/mail_attachments/'.$this->zip_file);
}
$zip = new \ZipArchive();
$zip->open($disk->put('storage/mail_attachments/'. $this->zip_file, ''), \ZipArchive::CREATE);
$download_file = file_get_contents(config('filesystems.disks.s3.url') . '/storage/mail_attachments/user_form_'.$this->uf_id.'.pdf');
$zip->addFromString(basename(config('filesystems.disks.s3.url') . '/storage/mail_attachments/user_form_'.$this->uf_id.'.pdf'), $download_file);
$zip->close();
We are hosting this on Laravel vapor and see this in the logs:
ZipArchive::close(): Failure to create temporary file: Read-only file system
The code above manages to create the zip file but it's empty when viewing it. This was working fine using public_paths for creating the zip.
Any help or advice would be appreciated!
Update
Managed to get it to work with the answer and Googled to find this thread which gave extra steps for making the zip https://laracasts.com/discuss/channels/vapor/zipping-file-on-laravel-vapor
You don't have access to local file storage on lambda as it's serverless.
Create a new disk in your config/filesystem.php
'tmp' => [
'driver' => 'local',
'root' => env('USE_LAMBDA_STORAGE', true) ? "/tmp" : storage_path('app/temp'),
'url' => env('USE_LAMBDA_STORAGE', true) ? "/tmp" : storage_path('app/temp'),
],
Create the zip file there by using $disk = Storage::disk('tmp');
.