Making TimThumb.php work with WPMU
It has taken almost 16 hours dissecting the wpmu system after being semi familiar with the basic wordpress setup. There aren’t nearly as many people who use wpmu as opposed to wp so troubleshooting becomes tough and you begin to rely on yourself to figure it out. I’ve done search across the net for hours seeing if there is a solution, but to no avail. Now that I’ve figured it out I have to pass it on.
First off, if you’ve made any changes to the timthumb.php script, you’re on your own. So I’m going to start with the original script which you can download from Darren Hoyt‘s blog. I created a folder inside my theme called scripts. Inside scripts we have timthumb.php and another folder called cache set to chmod 0777 permissions. Some people have told me you need to set the timthumb.php to 0777 but I have found that to be untrue as it doesn’t matter AND creates a security flaw. I recommend keeping the script at 0755 (default).
Start by making sure the script works. To do this access the file directly with no variables set. It should give you an error with ‘No Image Specified’. Here is an example:
This lets us know the script is working no problem. According to the creator’s instructions, we are told to use the following to call an image:
<img src="/scripts/timthumb.php?src=/images/whatever.jpg&h=150&w=150&zc=1" alt="" />
The idea is to add a custom value field named “Image” (with a capital i – there is a difference between image and Image) with the value pointing to the location of your image. In my case, when I upload an image using wordpress it puts it in the following place:
If you use this path in your image src using wpmu you’ll get the following error even though the image IS there:
//files/2008/08/file.gif not found.
Reason for this happening is because in the default .htaccess for wpmu, the modrewrite article is used to change the /files/ to wp-content/blogs.php?file=location. In return, the blogs.php file actually pulls the image from a totally seperate directory. In my case, it is blog 1. So the image is actually located
I’m not a programmer, i just learn what i need to know to make things work. So i cannot tell you why all these rewrites are causing the image to not display. Anyways, for the fix. In the code of your template you must put this:
<img src = scripts/timthumb.php?src=http://www.sheaallen.com/wp-content/blogs.dir/1/<?php $values = get_post_custom_values(“Image”); echo $values; ?>&w=300&h=275&zc=1&q=100>
In my case, the custom Image value would be files/2008/08/file.gif (no slash at the beginning). Yes, there may be other ways to do this, possibly something simpler and easier on the end user, but this method DOES work and it currently doesn’t have any flaws. If you have another way to make this fix, please let me know. Once again, I’m not a programmer but I’ll attempt to help you if it still doesn’t work. Good luck!
This code will work better than hardcoding your web address and blog directory as shown above:
<?php bloginfo(‘template_url’);?>/scripts/timthumb.php?w=203px&h=138&src=<?php bloginfo(‘url’); ?>/wp-content/blogs.dir/<?php echo $wpdb->blogid; ?>/<?php $values = get_post_custom_values(”Image”); echo $values; ?>&zc=1&q=100