Return to Snippet

Revision: 62039
at January 30, 2013 02:28 by tacudtap


Updated Code
//check if tilde is found in src
if(strstr($this->param('src'),'~'))
{
   $url_parts = explode('/',$this->param('src'));
 
   foreach($url_parts as $url_part)
   {
      //do not include any part with a ~ when building new url
      if(!strstr($url_part,'~'))
      {
         $new_dev_url .= $url_part.'/';
      }
   }
 
   //remove trailing slash
   $new_dev_url = substr($new_dev_url,0,-1);
 
   $this->src = $new_dev_url;
}
else
{
   $this->src = $this->param('src');
}

Revision: 62038
at January 30, 2013 02:24 by tacudtap


Initial Code
At line 209 you will find the code:

`$this->src = $this->param('src');`

Replace that with:

    //check if tilde is found in src
    if(strstr($this->param('src'),'~'))
    {
       $url_parts = explode('/',$this->param('src'));
     
       foreach($url_parts as $url_part)
       {
          //do not include any part with a ~ when building new url
          if(!strstr($url_part,'~'))
          {
             $new_dev_url .= $url_part.'/';
          }
       }
     
       //remove trailing slash
       $new_dev_url = substr($new_dev_url,0,-1);
     
       $this->src = $new_dev_url;
    }
    else
    {
       $this->src = $this->param('src');
    }

Initial URL
http://elementdesignllc.com/2012/01/how-to-fix-timthumb-using-a-virtual-directory-url-contains-tildes/

Initial Description
If you are using the [TimThumb](http://code.google.com/p/timthumb/ "TimThumb on Google Code") script with a URL the contains tildes (~) and images are breaking, here is the fix...

I did not create this snippet but found it extremely useful so I thought I'd make it available here. The URL listed is not mine but where I found it. Enjoy :-)

At line 209 (as of 01-29-13) in the script you will find the following line of code:

`$this->src = $this->param('src');`

Replace that line with the following snippet:

Initial Title
Fix Timthumb Script When Using a URL That Contains Tildes (~)

Initial Tags
php, script, images, directory

Initial Language
PHP