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