storagePath . '/pages/' . $chapterId; if (!is_dir($targetDir)) { mkdir($targetDir, 0755, true); } sort($localImagePaths); foreach ($localImagePaths as $index => $localPath) { $extension = pathinfo($localPath, PATHINFO_EXTENSION) ?: 'jpg'; $targetFile = sprintf('%s/%03d.%s', $targetDir, $index + 1, $extension); copy($localPath, $targetFile); } return $targetDir; } }