У меня есть следующий код для создания zip-архива.Как я могу проверить, действительно ли был создан архив?
Когда файлы не добавлены, вызов close
все еще возвращает true?
$profiles = $profileRepository->getProfiles()->get();
$fileName = time() . '-' . uniqid() . '-' . '.zip';
$filePath = storage_path('app/bulkdownloads/' . $fileName);
$zip = new ZipArchive;
if ($zip->open($filePath, ZipArchive::CREATE) === TRUE) {
foreach($profiles as $profile) {
if (file_exists(storage_path('app/' . $profile->file_path)))
$zip->addFile(storage_path('app/' . $profile->file_path), $profile->name . '-' . $profile->id . '.' . pathinfo($profile->file_path, PATHINFO_EXTENSION));
}
$res = $zip->close();
if ($res == true) {
$newFile = \App\File::create([
"name" => $fileName
"path" => 'bulkdownloads/' . $fileName,
"size" => filesize($filePath),
"mime_type" => mime_content_type($filePath),
]);
}
}