View Full Version : iframe refresh problem in IE

02-15-2006, 08:42 PM

Im trying to create a page for a picture framing site where users can upload images to see how they would look framed. The idea is that users will be able to change, among other things, the color of the mount used (I think what I'm calling a "mount" is called a "mat" in the US).

The user's image is sent to "upload.php" where it is resized and overlaid with a GD-constructed gif (with a transparent aperture) which represents the mount. All this is surrounded by a picture-frame constructed from small images with CSS. "upload.php" is displayed in an iframe within the main page.

From the main page, I'm sending variables in the url of "upload.php" (retrieved using $_GET) in order to change the color and shape of the mount. I'm also storing these variables using $_SESSION so their values are not lost when the user changes something else.

So far, all this works fine in Firefox but it only works in IE if I manually refresh the main page.

Here's the page for you to have a look at:

Try uploading an image. On the "Mounts 1" tab there are two links which change the shape of the mount, and on the "Mounts 2" tab the small colored images are links to change the mount color. They all work without a page-refresh in Firefox, but not in IE. Any idea why?

The upload.php file is a bit long to paste here so I've uploaded it as a text file to: http://www.winkleweb.org/picturegallery/upload.txt

I'm new to all this so any help would be much appreciated.



02-15-2006, 11:04 PM
Its because the mount is the same file for every selection (pic.gif), im assuming its generated dynamically? IE is caching the image, so every time that frame reloads it sees the same filename and just loads the one its already got rather than re requesting it from the server.

Im guessing your going to need to change how this works anyway because if two people try to use it at the same time they will both the accessing the same pic.gif, which will be changing every time someone clicks a mount.

There are much better ways to do this, but a quick work around is to stick a random string on the end of the image path, like this:

<img src="pic.gif?random=239487239472" style="border: 0;" width="400" height="307" />

The value of random can be generated automatically by php, use rand().

This is really just a hack though, and isnt fail safe.

Hope that at least points you in the right direction, if you need any more help just say.


P.S. The upload script doesn’t accept a file if the extension is in capitals.

02-15-2006, 11:22 PM
i can't imagine this is a php-issue.

by the way, in Opera, your site has the same problem. My first guess would be that it's a caching issue --> the images always have the same name, so some browsers will use the one from their cache instead of requesting a new one from the server.

to prevent caching, the easiest workaround is to add the time() value to your filename.

02-16-2006, 01:08 AM
Many thanks guys,

I included time() in both the name of the temporary GD image and in the output file name (formerly $pic.gif) and it now works in IE. At last!!! :)

However, I now have the problem of how to delete the images when they're no longer needed. I think I'll have to rethink exactly what I want to save in the $_SESSION. At the moment, all I'm saving is the file that tiles the images. I'm getting tired now though, I'll have a go in the morning.

Thanks again,


02-16-2006, 10:28 AM
However, I now have the problem of how to delete the images when they're no longer needed.
i think the most secure way is to run a cron every 30 minutes that requests a php page where you loop through the file-directory and that unlinks all files with a
filemtime($file) < time()-(30*60)

02-16-2006, 12:59 PM
Thanks raf,

Yes, I think a cron sounds like my best bet. Or is there a way I could detect that the user had left the page so I could unlink the last file stored in their $_SESSION? Or perhaps I could resort to a "Remove your image from the server" button?



02-16-2006, 02:15 PM
Or is there a way I could detect that the user had left the page so I could unlink the last file stored in their $_SESSION?
Not realy. If they close their browser or enter a new url, then this can't be detected by your server.
Unless you would for instance use a frame and then set an autorefresh (with a realy small interval) on one of the pages and keep track of when they last refreshed that page. But that is realy an ugly and resource-eating way.

Or perhaps I could resort to a "Remove your image from the server" button?
You can have such a button, but in addition to that, you still need the cron to remove the images from the users that didn't hit the button.
The button is only required if you realy have a high number of vistors and need to remove the space asap. That the images unnescecarely take up some space for maximum 30 minutes shouldn't have any impact on your servers performance.

If you realy have a hight number of isitors, then it would be best to define a maximum amount of space for all images, and to check if this wasn't reached before uploading a new immage + to run your cron more frequently.

02-16-2006, 05:17 PM
Hi raf,

I'm doing this for my sister's website. She has high hopes for it, but I don't know how popular it will be. I think a cron run every 30 minutes as you suggest would do the job.

Thanks for your help,