PHP How-ToPost your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.
You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
I have a very simple problem here that may or may not be solvable using PHP.
I recently did some redesigning on this image submission thing that I've got to make it completely object oriented.
Well that's not really the problem I have a new set-up that works beautifully. The problem appears to be with Interent Explorer, for some reason it won't cache an updated image... it continues to display the cache'd image even after its been changed on the server. Well I suppose its not really being changed on the server, cause it outputs from a database via a PHP script.
I had to get into the 'internet options' menu and turn off the cache all together in order to get the browser to ignore the cache'd copy. Which isn't really the best solution.
I am curious to know if there are headers that I could output, like a time that the file was created/modified, or something to that effect that will work with Internet Explorer's cache process.
Yeah, that sucks! The problem with looking for a solution that sends headers with an image is that IE won't request an image from the server if the same image is stored in the cache and is thought to be up-to-date.
This suggests that the only solution is a horribly inefficient one -- ensuring that IE download every changeable image, EVERY time.
But if that were really true, how would IE know that the image ever changed? I mean, take this simple test. Save an image on your server. Browse to it in IE. Overwrite that image with a different image (using the same filename). Refresh the browser. Bingo -- the new image displays.
There's got to be a tip-off going on. Clearly there ought to be a better way!
I suppose your best bet is to get a network traffic monitor (port sniffer, whatever) running on your machine, and look at the actual HTTP response from the server when making requests of actual images. Perhaps IE requests the images and decides whether or not to sever the download connection based on the data it gets in the headers...
If this is all too much work, you can just use the "no-cache" header for the easy way out.
There is another brutal hack, which is useful if you are simply doing an image upload on an Admin (i.e. backend) interface and simply want to show the site admins that the new image has, indeed, uploaded... Append an arbitrary new "querystring" to the tail end of the image's URL, i.e. "randomvariable = some value that will always be different, like what is returned from time();".
Because the URL has 'changed', IE will make a fresh request.
quote:Originally posted by quesadilla5
This fits the bill and appears to give me some flexibility.
Well none of these work for me i'm sorry to say. The problem appears to lie with IE though as when i updated my php page images they appear instantly in Opera. Updated images on this php will only appear if i force a refresh of the page which is crazy as the page had already reloaded once after the form was submit to upload the new image, so refreshing the same page twice seems like madness just to get IE working as it should do!
Any more ideas of how to prevent IE using old images in a dymanic page?
Yes i cleared the cache, the image url is output by php which is pretty standard, its not outputting a blob from a MySQL db or anything like that.
Although i earlier mentioned the page worked fine in Opera, this too isn't working 100% now for some reason. When i upload an image it moves the image to a structured directory and also creates a thumbnail of that image. Once the upload has been submitted either the thumbnail or both the image and the thumbnail display the old image but the dimensions / size of the image change to that of the new if that makes sense?...
Personally i'm quite happy using IE as i've not had an issue with it before and i always think it best to design for the populous who are going to be using it too.