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); Link to comment https://forums.phpfreaks.com/topic/181854-help-with-my-if-statement/ 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. Link to comment https://forums.phpfreaks.com/topic/181854-help-with-my-if-statement/#findComment-959089 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 Link to comment https://forums.phpfreaks.com/topic/181854-help-with-my-if-statement/#findComment-959117 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. Link to comment https://forums.phpfreaks.com/topic/181854-help-with-my-if-statement/#findComment-959120 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.