PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
function createThumbnail($srcFile, $destFile, $width, $quality = 75,$test=FALSE)
{
$thumbnail = '';
if (file_exists($srcFile) && isset($destFile))
{
$size = getimagesize($srcFile);
$w = number_format($width, 0, ',', '');
$h = number_format(($size[1] / $size[0]) * $width, 0, ',', '');
$thumbnail = copyImage($srcFile, $destFile, $w, $h, $quality);
$name=explode("/",$thumbnail);
$size=count($name);
}
$answer=basename($thumbnail);
if (basename($thumbnail)=="")
{
$answer= $name[$size-1];
}
// return the thumbnail file name on sucess or blank on fail
return $answer;
}
now I know thumbnail contains somethign because i put in an echo in the function and exit so I could see it. however, the function is not returning it. any theories on why?
It appears that if your $srcFile does not exist, or $destFile is not set, then you will be calling $name[$size-1] even though $name and $size are undefined. You might want to just change your first if to return false if it fails. Even though thats not technically an error, its good programming practice to watch out for that. You should turn on notices on your dev server, it should catch alot of those things.
Secondly, to get to your question, what is the value of answer within your function? Echo that at each step and see what it is, not just $thumbnail.