hasCustomProperty('wp_original_path')) { return $this->getWordPressPath($media); } // 新上傳的文件使用標準路徑: media/{model_id}/ return $this->getBasePath($media) . '/'; } public function getPathForConversions(Media $media): string { return $this->getPath($media) . 'conversions/'; } public function getPathForResponsiveImages(Media $media): string { return $this->getPath($media) . 'responsive/'; } protected function getWordPressPath(Media $media): string { // 從 WordPress 路徑中提取年月目錄 // 例如: wp-content/uploads/2024/03/image.jpg -> uploads/2024/03/ $originalPath = $media->getCustomProperty('wp_original_path'); if (preg_match('#uploads/(\d{4}/\d{2})/#', $originalPath, $matches)) { return 'uploads/' . $matches[1] . '/'; } // 如果無法解析,使用標準路徑 return $this->getBasePath($media) . '/'; } protected function getBasePath(Media $media): string { return 'media/' . $media->getKey(); } }