Skip to content

Commit

Permalink
Better detection of remote images
Browse files Browse the repository at this point in the history
Weeds out bad paths/URLs like //directory/image.jpg
  • Loading branch information
oo12 committed Aug 28, 2013
1 parent e2f8dc6 commit b6f847d
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions core/components/phpthumbof/model/phpthumbof.class.php
Expand Up @@ -92,8 +92,8 @@ public function debugmsg($msg, $phpthumbDebug = FALSE) {
* Returns the filename of the cached image on success or $src on failure
*/
public function createThumbnail($src, $options) {
if ( preg_match('/^(?:https?:)?\/\/(.+?)\/(.+)/i', $src, $matches) ) { // if we've got a remote image to work with
$file = $this->config['cachePath'] . preg_replace("/[^\w\d\-_\.]/", '-', "{$matches[1]}-{$matches[2]}"); // generate a cache filename
if ( preg_match('/^(?:https?:)?\/\/((?:.+?)\.(?:.+?))\/(.+)/i', $src, $matches) ) { // if we've got a remote image to work with
$file = $this->config['cachePath'] . preg_replace('/[^\w\d\-_\.]/', '-', "{$matches[1]}-{$matches[2]}"); // generate a cache filename
if (!file_exists($file)) { // if it's not in our cache, go get it
$fh = fopen($file, 'wb');
if (!$fh) {
Expand Down

0 comments on commit b6f847d

Please sign in to comment.