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

Recursive search filename #67

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
19 changes: 13 additions & 6 deletions src/Intervention/Image/ImageCacheController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Intervention\Image\ImageManager;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Http\Response as IlluminateResponse;
use Symfony\Component\Finder\Finder;
use Config;

class ImageCacheController extends BaseController
Expand Down Expand Up @@ -125,17 +126,23 @@ private function getTemplate($template)
private function getImagePath($filename)
{
// find file
$finder = new Finder;

foreach (config('imagecache.paths') 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;
}
$finder->in($path);
}

$finder->files()->name($filename);

$files = iterator_to_array($finder->getIterator());

if (count($files)) {
return array_keys($files)[0];
}

// file not found
abort(404);

}

/**
Expand Down