Improve asset import using ZipArchive::extractTo()
This commit is contained in:
@@ -72,22 +72,13 @@ class AssetController extends Controller
|
|||||||
|
|
||||||
$storagePublic = storage_path('app/public');
|
$storagePublic = storage_path('app/public');
|
||||||
|
|
||||||
for ($i = 0; $i < $zip->numFiles; $i++) {
|
if (!is_dir($storagePublic)) {
|
||||||
$filename = $zip->getNameIndex($i);
|
mkdir($storagePublic, 0777, true);
|
||||||
$fileinfo = $zip->statIndex($i);
|
}
|
||||||
|
|
||||||
if ($fileinfo['crc'] == 0) {
|
if ($zip->extractTo($storagePublic) !== true) {
|
||||||
continue;
|
$zip->close();
|
||||||
}
|
return response()->json(['message' => 'Failed to extract assets from ZIP'], 500);
|
||||||
|
|
||||||
$targetPath = $storagePublic.DIRECTORY_SEPARATOR.$filename;
|
|
||||||
$targetDir = dirname($targetPath);
|
|
||||||
|
|
||||||
if (!is_dir($targetDir)) {
|
|
||||||
mkdir($targetDir, 0775, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
copy('zip://'.$zipPath.'#'.$filename, $targetPath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$zip->close();
|
$zip->close();
|
||||||
|
|||||||
Reference in New Issue
Block a user