sac0o01 Posted July 9, 2010 Share Posted July 9, 2010 I am creating an image file through GD. It successfully creates the file with a random file name. //define file name $rand = rand(1,100000); $filename = 'temp/' . $rand . '.png'; Upon the script completion it directs back to the index page where the image should be displayed but it does not. <img src="<?php echo 'temp/' . $rand . '.png';?>" /> I was using $PHPSESSID to create and display the image and it worked fine except that IE held the image in cache and required a hard refresh to display the new image. Any suggestions how to get the random image src working, or maybe a better way of handling the entire process?? Quote Link to comment Share on other sites More sharing options...
joel24 Posted July 10, 2010 Share Posted July 10, 2010 you're probably better off using time() than rand(), this will return a unix timecode (seconds passed since 1970, jan 1st), so it will change every second. //define file name $filename = 'temp/' . time() . '.png'; and for the index page script which displays the image, how is the $rand variable being passed from the upload script to the index page?! you may need to store it in the session, and IE shouldn't hold the image in the cache if it has a new file name?! Don't quote me on this however, sounds like something IE would do. Quote Link to comment Share on other sites More sharing options...
sac0o01 Posted July 10, 2010 Author Share Posted July 10, 2010 Upon submit the page runs script.php and then uses header("Location....") to return to the index page. I am afraid this is causing the set variable to be wiped out. I may have to stick with the session named file and find a way to force refresh each time the form is changed. Quote Link to comment Share on other sites More sharing options...
joel24 Posted July 10, 2010 Share Posted July 10, 2010 either that or you can pass the variable in the URL, i.e. //define file name $filename = 'temp/' .time() . '.png'; $urlFile = urlencode($filename); header("index.php?img=$urlFile"); then on index.php, to display image (providing all if (isset($_GET['img'])) { $imagePath = urldecode($_GET['img']); echo "<img src='$imagePath' />"; } 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.