У меня есть функция для загрузки zip -файла с папками или без него на основе File_type_id. Однако, когда file_type_id - 1, мой сервер возвращает пустой 200 -й ответ. И это не происходит в моей локальной среде только на моем сервере Ubuntu. Когда я смотрю на папку Temp, я создал zip -файл, и все файлы находятся в ней, когда я разкапливаю ее в командной строке. Так что мой вопрос будет, почему это поведение существует и если у кого -то есть решение? В журналах Laravel.log или Nginx/Apache также ничего нет.
public function downloadZip($file_type, $resId)
{
$reservation = Reservation::with('contact.insurer')->where('id', $resId)->first();
if (Auth::user()->hasRole('verzekeraar')) {
$contact = Auth::user()->userable;
if ($contact->insurer_id != $reservation->contact->insurer_id) {
return AppJsonResponse::UnAuthorized('U heeft geen rechten voor dit dossier.');
}
}
$files = [];
$dirs = [];
if ($file_type == 2) {
$files = $reservation->files;
} else {
$dirs = Folder::whereNull('parent_id')->where('reservation_id', $reservation->id)->get();
$files = File::whereNull('parent_id')->where('reservation_id', $reservation->id)->where('file_type_id', 1)->get();
}
$zip_file = storage_path('app/tmp/wrapper.zip');
// Ensure tmp directory exists
if (!file_exists(storage_path('app/tmp'))) {
mkdir(storage_path('app/tmp'), 0755, true);
}
// Initializing PHP class
$zip = new \ZipArchive();
if ($zip->open($zip_file, \ZipArchive::CREATE | \ZipArchive::OVERWRITE) !== TRUE) {
\Log::error("Cannot open \n");
return AppJsonResponse::Error('ZIP creation failed.');
}
if ($file_type == 2) {
foreach ($files as $file) {
if ($file->file_type_id == $file_type) {
$zip->addFile(Storage::disk('private')->getDriver()->getAdapter()->applyPathPrefix($file->path), 'storage/' . $file->name . '.' . strtolower($file->ext));
}
}
} else {
$ultPath = 'storage/';
$this->zipDocuments($dirs, $files, $ultPath, $reservation->id, $zip);
}
if (!$zip->close()) {
\Log::error("Failed to close the zip file.");
} else {
\Log::debug("Successfully closed zip file: $zip_file");
}
if (file_exists($zip_file)) {
Log::info("File size of ZIP: " . filesize($zip_file));
return response()->download($zip_file, 'wrapper.zip', [
'Content-Type' => 'application/zip',
]);
} else{
\Log::error('ZIP file is missing or too small: ' . $zip_file);
return AppJsonResponse::Error('ZIP creation failed.');
}
}
Подробнее здесь: https://stackoverflow.com/questions/796 ... ownloading
Zip -файл Laravel не загружает ⇐ Php
Кемеровские программисты php общаются здесь
1750310887
Anonymous
У меня есть функция для загрузки zip -файла с папками или без него на основе File_type_id. Однако, когда file_type_id - 1, мой сервер возвращает пустой 200 -й ответ. И это не происходит в моей локальной среде только на моем сервере Ubuntu. Когда я смотрю на папку Temp, я создал zip -файл, и все файлы находятся в ней, когда я разкапливаю ее в командной строке. Так что мой вопрос будет, почему это поведение существует и если у кого -то есть решение? В журналах Laravel.log или Nginx/Apache также ничего нет.
public function downloadZip($file_type, $resId)
{
$reservation = Reservation::with('contact.insurer')->where('id', $resId)->first();
if (Auth::user()->hasRole('verzekeraar')) {
$contact = Auth::user()->userable;
if ($contact->insurer_id != $reservation->contact->insurer_id) {
return AppJsonResponse::UnAuthorized('U heeft geen rechten voor dit dossier.');
}
}
$files = [];
$dirs = [];
if ($file_type == 2) {
$files = $reservation->files;
} else {
$dirs = Folder::whereNull('parent_id')->where('reservation_id', $reservation->id)->get();
$files = File::whereNull('parent_id')->where('reservation_id', $reservation->id)->where('file_type_id', 1)->get();
}
$zip_file = storage_path('app/tmp/wrapper.zip');
// Ensure tmp directory exists
if (!file_exists(storage_path('app/tmp'))) {
mkdir(storage_path('app/tmp'), 0755, true);
}
// Initializing PHP class
$zip = new \ZipArchive();
if ($zip->open($zip_file, \ZipArchive::CREATE | \ZipArchive::OVERWRITE) !== TRUE) {
\Log::error("Cannot open \n");
return AppJsonResponse::Error('ZIP creation failed.');
}
if ($file_type == 2) {
foreach ($files as $file) {
if ($file->file_type_id == $file_type) {
$zip->addFile(Storage::disk('private')->getDriver()->getAdapter()->applyPathPrefix($file->path), 'storage/' . $file->name . '.' . strtolower($file->ext));
}
}
} else {
$ultPath = 'storage/';
$this->zipDocuments($dirs, $files, $ultPath, $reservation->id, $zip);
}
if (!$zip->close()) {
\Log::error("Failed to close the zip file.");
} else {
\Log::debug("Successfully closed zip file: $zip_file");
}
if (file_exists($zip_file)) {
Log::info("File size of ZIP: " . filesize($zip_file));
return response()->download($zip_file, 'wrapper.zip', [
'Content-Type' => 'application/zip',
]);
} else{
\Log::error('ZIP file is missing or too small: ' . $zip_file);
return AppJsonResponse::Error('ZIP creation failed.');
}
}
Подробнее здесь: [url]https://stackoverflow.com/questions/79671565/laravel-zip-file-not-downloading[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия