Problems, need help? Have a tip or advice? Post it here.
3 posts Page 1 of 1
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:

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.
Thank you for posting your solution, IllyaMoskvin.
Creating a separate folder can be a useful thing to do.

As regards to the spaces in filename, you said
My client uploads images with spaces in their filenames
I think your client is not using Couch's uploader (KCFinder or the older one) as in that case Couch would have normalized the filenames to replace the spaces with hyphens.

Therefore, I don't think this could be termed a bug as the cms:thumbnail tag expects images to have been uploaded through Couch and assumes the names are normalized.

Thanks.
Ah! Sorry, you're absolutely right. Looking back on my posts, I modified functions.php to stop automatic hyphenation and lowercase during file upload. No wonder it broke on me!

Thank you for your time!
3 posts Page 1 of 1