Skip to content
This repository has been archived by the owner on Dec 9, 2023. It is now read-only.

Priority file source location for configured templates are introduced #70

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/Intervention/Image/ImageCacheController.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public function getResponse($template, $filename)
*/
public function getImage($template, $filename)
{
$path = $this->getImagePath($filename, $template);
$template = $this->getTemplate($template);
$path = $this->getImagePath($filename);

// image manipulation based on callback
$manager = new ImageManager(Config::get('image'));
Expand Down Expand Up @@ -122,8 +122,20 @@ private function getTemplate($template)
* @param string $filename
* @return string
*/
private function getImagePath($filename)
private function getImagePath($filename, $template=null)
{
// find file in priority locations
if(!is_null($template) && array_key_exists($template, config('imagecache.priority_paths'))) {
foreach(config("imagecache.priority_paths.$template") as $path) {
// don't allow '..' in filenames
$image_path = $path.'/'.str_replace('..', '', $filename);
if (file_exists($image_path) && is_file($image_path)) {
// file found
return $image_path;
}
}
}

// find file
foreach (config('imagecache.paths') as $path) {
// don't allow '..' in filenames
Expand Down
24 changes: 24 additions & 0 deletions src/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,30 @@
public_path('images')
),

/*
|--------------------------------------------------------------------------
| Priority Storage Paths
|--------------------------------------------------------------------------
|
| Here you can associte some image source paths
| specific to a particular tempalate.
|
| Example:
|
| 'blog' => array(
| public_path('images/blog'),
| public_path('upload/blog'),
| ),
| 'profile' => array(
| public_path('upload/profile'),
| ),
|
*/

'priority_paths' => array(

),

/*
|--------------------------------------------------------------------------
| Manipulation templates
Expand Down