Hello all!
Just wanted to report a bug, along with a possible solution. My client uploads images with spaces in their filenames, and I retrieve those images using the <cms:thumbnail /> tag. I had a bunch of errors along these lines:
I found that this was caused by the spaces in the filenames, which seem to have been saved in the database with the appropriate URL encoding (i.e. the spaces are replaced by %20's).
I solved this issue by adding the following code block in timthumb.php, right before it checks for mime type:
Hopefully this will help out someone encountering the same problem. Cheers!
Edit: On a related note, I wanted the thumbnails to be saved to a sub-folder (named by the width/height) instead of being in the same folder as the images. Because all the images are square, I'm not afraid that it will create too many sub-folders. If your case is different, but you are only limiting the thumbnail creation by one variable (width or height), then you can change the $dir_name variable to only account for that one variable (e.g. omitting round($new_height)). Anyway, here is the code I replaced in timthumb.php:
Edit again: Oops, forgot to add a forward slash to the return. Fixed.
Just wanted to report a bug, along with a possible solution. My client uploads images with spaces in their filenames, and I retrieve those images using the <cms:thumbnail /> tag. I had a bunch of errors along these lines:
- Code: Select all
Warning: finfo_file(C:/wamp/www/.../72.145.1%20thmb.jpg): failed to open stream: No such file or directory in C:\wamp\www\...\couch\includes\timthumb.php on line 317
I found that this was caused by the spaces in the filenames, which seem to have been saved in the database with the appropriate URL encoding (i.e. the spaces are replaced by %20's).
I solved this issue by adding the following code block in timthumb.php, right before it checks for mime type:
- Code: Select all
// get mime type of src
$src = urldecode( $src );
$mime_type = mime_type($src);
Hopefully this will help out someone encountering the same problem. Cheers!
Edit: On a related note, I wanted the thumbnails to be saved to a sub-folder (named by the width/height) instead of being in the same folder as the images. Because all the images are square, I'm not afraid that it will create too many sub-folders. If your case is different, but you are only limiting the thumbnail creation by one variable (width or height), then you can change the $dir_name variable to only account for that one variable (e.g. omitting round($new_height)). Anyway, here is the code I replaced in timthumb.php:
- Code: Select all
// Create filename if not provided one (happens only for thumbnails)
if( !$dest ){
$path_parts = $FUNCS->pathinfo( $src );
$thumb_name = $path_parts['filename'] . '.' . $path_parts['extension'];
$dir_name = round($new_width) . 'x' . round($new_height);
if( !file_exists( $path_parts['dirname'] . '/' . $dir_name ) )
mkdir( $path_parts['dirname'] . '/' . $dir_name );
$thumbnail = $path_parts['dirname'] . '/' . $dir_name . '/' . $thumb_name;
if( $check_thumb_exists && file_exists($thumbnail) ){
return $dir_name . '/' . $thumb_name;
}
}
Edit again: Oops, forgot to add a forward slash to the return. Fixed.