Load relative path of images instead of <?php echo $img ?>

590 views Asked by At

The timthumb function is not working after the security setting of web server is raised. Images with "http://...." in URL are blocked.

I have found that <?php echo $img ?> was used to load the image. Original code:

<img src="<?php bloginfo('template_directory'); ?>/scripts/timthumb.php?h=100&amp;w=100&amp;zc=1&amp;src=<?php echo $img ?>" alt="<?php the_title_attribute(); ?>" width="100" height="100" />

Would someone please tell me how can I modify the code so that instead of

http://domain.com/wp-content/themes/a/scripts/timthumb.php?h=100&w=100&zc=1&src=http://domain.com/wp-content/uploads/thumbnail.jpg

the image URL will be

http://domain.com/wp-content/themes/a/scripts/timthumb.php?h=100&w=100&zc=1&src=../wp-content/uploads/2013/10/thumbnail.jpg

?

The code inside timthumb.php is super long. I will post the code if it's needed.

I know almost nothing about php code and only use plugins to build Wordpress websites. You would have save my life. Thank you very very much!

1

There are 1 answers

1
Gopherkhan On BEST ANSWER

It depends on where it is getting $img value from. If this is just a field on your article (through the extra parameters on the bottom), you could simply alter the url in your post. Alternatively, you could process the path, stripping out the http://domain.com/ and replace it with ../,

a la:

$img = str_replace("http://domain.com/", "../", $img);

just before echoing it out on to the page.