views:

33

answers:

2

I'm writing a wordpress plugin, and using this script to resize images: Timthumb

This script uses absolute paths, but I can't get it to work for me; I've triple-checked all my paths but still nothing.

Here is my code:

$plugin_dir_name = "my-plugin";

$pathTimThumb = WP_PLUGIN_URL . '/' . $plugin_dir_name . '/timthumb.php';
$pathToUpload = WP_CONTENT_URL.'/uploads/'.$plugin_dir_name;
$hImg = 150;
$wImg = 150;

....

$myImage = '<img class="thumb" src="'.$pathImageThumb.'?src='.$pathToUpload.'/'.$allImages[$i].'&h='.$hImg.'&w='.$wImg.'&zc=1" alt="">';

In firebug I get this URL:

<img alt="" src="http://localhost/mu/wp-content/plugins/my-plugin/timthumb.php?src=http://localhost/mu/wp-content/uploads/my-plugin/car___1/26zhoar5.jpg&amp;amp;h=150&amp;amp;w=150&amp;amp;zc=1" class="thumb">

Where is the mistake?

A: 

WP_CONTENT_URL is a url, not an absolute path. Use WP_CONTENT_DIR instead.

John P Bloch
I know that,also try that.Image is loaded in browser when just paste this url in browser http://localhost/mu/wp-content/uploads/my-plugin/car___1/26zhoar5.jpg. Dont know where is mistake,it is annoying :(
A: 

TimThumb tries to determine the local path of the image by stripping out http://CURRENT_HOST.tld from the beginning of the src parameter.

Since you're running on localhost it might be getting a little confused and falsely calculating it as an external image. I doubt this is the case (I checked the source and it should be OK), but it's an educated guess.

Have you tried reading the HTTP response headers from http://localhost/mu/wp-content/plugins/my-plugin/timthumb.php?src=http://localhost/mu/wp-content/uploads/my-plugin/car___1/26zhoar5.jpg&amp;amp;h=150&amp;amp;w=150&amp;amp;zc=1?

If not, use HttpFox for FireFox and post back the results.

TheDeadMedic
When I upload plugin on site it works fine,it just wont work on localhost,I dont know why.Tnx for help.
Yah, so have you checked the HTTP response headers? As I said, the fact you're running under localhost is probably *why* it's not working.
TheDeadMedic
After reinstalling XAMPP it is working fine also and in a localhost.Tnx for your time and responses.