Suchy Posted June 1, 2007 Share Posted June 1, 2007 So I have a simple function (show.php) that resizes & displays images onto a page. <?php session_start(); $link = $_SESSION['link']; $x_max = $_SESSION['x_max']; $photo = open ( $link ); function open ($temp) { $im = @imagecreatefromjpeg($temp); if ($im !== false) { return $im; } $im = @imagecreatefromgif($temp); if ($im !== false) { return $im; } $im = @imagecreatefrompng($temp); if ($im !== false) { return $im; } return false; } $x = imagesx($photo); $y = imagesy($photo); $y_max = $y * ($x_max/$x); $resize = imagecreatetruecolor($x_max, $y_max); imagecopyresampled($resize, $photo, 0, 0, 0, 0, $x_max, $y_max, $x, $y); imagejpeg($resize); ?> And it is called inside a loop: <?php foreach($entriesResults as $temp_img) { session_start(); $url = $temp_img['url']; $_SESSION['link'] = $url; $max = 75; $_SESSION['x_max'] = $max; ?> <img src="show.php"> </img> <? } ?> This works when I limit the query to just 1 item. But when there is no limit, insted of 20 unique pictures. The last image is printed 20 times. Why is this happening ? Quote Link to comment https://forums.phpfreaks.com/topic/53875-solved-strnge-function-behavior/ Share on other sites More sharing options...
dough boy Posted June 1, 2007 Share Posted June 1, 2007 I ran into something similar before. Try making it: <img src="show.php?<?=rand()?>" /> Basically your web page is caching (I think you probably are using IE) and the random number "tells" the browser that it is a unique image. Also the "proper" way to close an img tag is with a /> as there is no closing tag. Quote Link to comment https://forums.phpfreaks.com/topic/53875-solved-strnge-function-behavior/#findComment-266372 Share on other sites More sharing options...
Suchy Posted June 1, 2007 Author Share Posted June 1, 2007 That,s not it. I still get the same problem in IE 6, Firefox 2 and Opera 9 Quote Link to comment https://forums.phpfreaks.com/topic/53875-solved-strnge-function-behavior/#findComment-266393 Share on other sites More sharing options...
per1os Posted June 1, 2007 Share Posted June 1, 2007 You have to have a way to call the file from the show.php try this man. <?php foreach($entriesResults as $temp_img) { $url = $temp_img['url']; $max = 75; echo '<img src="show.php?link=' . $url . '&max=' . $max . '"> </img>'; } ?> <?php $link = $_GET['link']; $x_max = $_GET['x_max']; $photo = open ( $link ); function open ($temp) { $im = @imagecreatefromjpeg($temp); if ($im !== false) { return $im; } $im = @imagecreatefromgif($temp); if ($im !== false) { return $im; } $im = @imagecreatefrompng($temp); if ($im !== false) { return $im; } return false; } $x = imagesx($photo); $y = imagesy($photo); $y_max = $y * ($x_max/$x); $resize = imagecreatetruecolor($x_max, $y_max); imagecopyresampled($resize, $photo, 0, 0, 0, 0, $x_max, $y_max, $x, $y); imagejpeg($resize); ?> Try that your code was flawed because you were not storing it in an array, and the show.php does not get called until the entire page is displayed which as it happens would be calling your last session entry. Remember php is PRE HYPER-TEXT PROCESSING, means it processes everything first before it gets sent to the browser. Anyhow that should work for you. Quote Link to comment https://forums.phpfreaks.com/topic/53875-solved-strnge-function-behavior/#findComment-266407 Share on other sites More sharing options...
Suchy Posted June 1, 2007 Author Share Posted June 1, 2007 That's also not it, now the images are not showing up at all. (I get the white box with red X) Is it because the link is so long that it is not displayed in whole in the status bar? Quote Link to comment https://forums.phpfreaks.com/topic/53875-solved-strnge-function-behavior/#findComment-266422 Share on other sites More sharing options...
per1os Posted June 1, 2007 Share Posted June 1, 2007 <?php foreach($entriesResults as $temp_img) { $url = $temp_img['url']; $max = 75; echo '<img src="show.php?link=' . $url . '&x_max=' . $max . '"> </img>'; } ?> Did not see that $max was turned into $x_max on the next page. If that does not work, post some of the < img code the script is producing, it can be fun sometimes to code blind, but very inefficient. Quote Link to comment https://forums.phpfreaks.com/topic/53875-solved-strnge-function-behavior/#findComment-266460 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.