php_beginner_83 Posted November 17, 2009 Share Posted November 17, 2009 Hi All I have an If() statement and it's not returning the result I want and I can't figure out why. I have printed values out to screen in a test program but I can't get this to work. I really need some advice. Thanks in advance. The input string will be 'images\alcatraz.jpg' What I want to happen is, if the input string has 'images\' in front of it I want to strip that off and just use 'alcatraz.jpg'. If it doesn't have 'images\' in front then I want to add 'thumbs\'. This is my code.. header("Content-type: image/png"); $dir = "thumbs/"; $filename = $_GET['image']; $thumbWidth = 50; $thumbHeight = 50; $substr = substr($filename, 0, 6); $len = strlen($filename); if($substr === "images") { $img = imagecreatefromjpeg(substr($filename, 8, $len); } else { // load image $img = imagecreatefromjpeg($dir . $filename); } // get image size $width = imagesx($img); $height = imagesy($img); // find wide picture if ($width > $height) { $newWidth = $thumbWidth; $newHeight = $thumbWidth * ($height/$width); } else { $newWidth = $thumbHeight * ($width/$height); $newHeight = $thumbHeight; } // create temporary image $tempImg = imagecreatetruecolor($newWidth, $newHeight); // create the thumbnail imagecopyresampled($tempImg, $img, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height); // output thumbnail imagepng($tempImg); Quote Link to comment Share on other sites More sharing options...
Adam Posted November 17, 2009 Share Posted November 17, 2009 Instead of: substr($filename, 8, $len) You need: substr($filename, 7) Note you don't need to add the length of the string in the third parameter as the default behavior will capture to the end of the string. Quote Link to comment Share on other sites More sharing options...
php_beginner_83 Posted November 17, 2009 Author Share Posted November 17, 2009 Thanks for the suggestion. I tried it and still it's not working Quote Link to comment Share on other sites More sharing options...
Adam Posted November 17, 2009 Share Posted November 17, 2009 Try removing the header content type and seeing if there's an obvious error, or check the error log if you can. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.