The code returns an error when the image path has a space on it. How to correct it through the code?
<p>The following code returns an eroor when the $image/$imgsrc has a space on it's path. For example www.domain.com/my pic.gif</p>

<p>However if you add a %20 in it, works correctly. How can I modify it so when the image has a space to run correct without editing the path?</p>

<p>Thank you!</p>

<pre><code>&lt;?php function resizeImg($imgsrc ,$maxW='*', $maxH='*', $allowScaleUp=0, $returnHTML="alt='image'"){
 if($s=getimagesize($imgsrc)){
  $oW=$s[0];$oH=$s[1];
  if(($oW&gt;$maxW &amp;&amp; $maxW!='*') || ($oH&gt;$maxH &amp;&amp; $maxH!='*') || $allowScaleUp){//if resize is needed:
   if($maxW &amp;&amp; $maxH=='*'){ //constrain by width:
    $proportion=$oH/$oW;
    $w=$maxW;
    $h=$maxW*$proportion;   
   }else if($maxH &amp;&amp; $maxW=='*'){ //constrain by height:
    $proportion=$oW/$oH;
    $h=$maxH;
    $w=$maxH*$proportion;
   }else if(!$maxW &amp;&amp; $maxH){ //constrain by smallest side:
    return($oW&gt;$oH ? resizeImg($imgsrc, '*', $maxH, $allowScaleUp, $returnHTML) : resizeImg($imgsrc, $maxW, '*', $allowScaleUp, $returnHTML));
   }else if($maxW &amp;&amp; !$maxH){ //constrain by largest side:
    return($oW&gt;$oH ? resizeImg($imgsrc, $maxW, '*', $allowScaleUp, $returnHTML) : resizeImg($imgsrc, '*', $maxH, $allowScaleUp, $returnHTML));
   }else{
    return($maxW&gt;$maxH ? resizeImg($imgsrc, '*', $maxH, $allowScaleUp, $returnHTML) : resizeImg($imgsrc, $maxW, '*', $allowScaleUp, $returnHTML));
   }
  }else{
   $w=$oW;$h=$oH;
  }
  //echo "orig: ".$oW."x:".$oH."&lt;br /&gt;max: ".$maxW."x".$maxH."&lt;br /&gt;new: ".$w."x".$h."&lt;br /&gt;"; //debug
  $w=round($w); $h=round($h);
  return ($returnHTML ? "&lt;img src='$imgsrc' width='$w' height='$h' $returnHTML /&gt;" : array(0=&gt;$w,1=&gt;$h,"width"=&gt;$w,"height"=&gt;$h));
 }else{//file does not exist or is not an image:
  return false;
 }
}
?&gt;


&lt;?php echo resizeImg($picture,250,'*') ?&gt;
</code></pre>
