Forum Moderators: coopster

Message Too Old, No Replies

Image Upload Problem

Script works, but image not refreshed after upload

         

beaudeal

9:03 am on Dec 13, 2006 (gmt 0)

10+ Year Member



Hi Everyone,

I've written a script to upload images to my server. Everything works perfect so I don't think theres a need to add code here. However one issue I'm having is that after the script executes, the page has to be manually refreshed in order for the new picture to show up; otherwise, the old picture is still there. After my script I have added a header("Location: picture.php") line to refresh from the script, but this still doesn't work. Any ideas?

Thanks so much!

PS. if it is relevant, i'm using the unlink function and the copy function to take off the old picture and add the new one.

omoutop

9:16 am on Dec 13, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Try to clean any array still in page (especially the $_FILE one).

Use clearstatcache() also won't hurt.

mcibor

4:45 pm on Dec 13, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I presume the problem is with browser cache, not the php.

Try to send the headers:

PHP scripts often generate dynamic content that must not be cached by the client browser or any proxy caches between the server and the client browser. Many proxies and clients can be forced to disable caching with:

<?php
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
?>

Michal

beaudeal

3:08 pm on Dec 14, 2006 (gmt 0)

10+ Year Member



hey guys thanks for the feedback -- i added the header stuff and it has fixed it in firefox, but no luck in IE6...i'm guessing this is IEs fault though...if you have any other suggestions let me know

thanks again!

mattcg

4:43 pm on Dec 14, 2006 (gmt 0)

10+ Year Member



Setting HTTP headers on the PHP file is useless unless you are using fpassthru to load the image or the image is base64 encoded in the HTML. You have to set the headers on the image file itself.

If you are using Apache you can use mod_expires [httpd.apache.org] together with an ExpiresByType [httpd.apache.org] declaration in your virtual host conf.


<location /uncacheable_images/>
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpeg "modification"
</IfModule>
</location>

hossa

10:37 pm on Dec 14, 2006 (gmt 0)

10+ Year Member



Try to add a variable after the url like this:

<img src="yourimage.jpg?<?PHP echo time();?>" border="0" alt="" />

should work fine in every browser.