0

I have a little web with two files: a index.html that only shows a image and a link to the second file named as change-image.php. The latter contain a form to upload a new image file to replace the image showed by index.html. It also process the form, renaming the new image to image.jpg and redirecting to index.html to show it. Looks like:

<?php
if (isset($_FILES['file'])) {
    move_uploaded_file($_FILES['file']['tmp_name'], 'image.jpg');
    header('Location: index.html');
    exit();
}

echo <<<END
...
   <form action="change-image.php" method="post" enctype="multipart/form-data">
      <input type="file" name="file" id="file"><br>
      <input type="submit" name="submit" value="Submit">
   </form>
...
END;

The problem is that i get the same first image. Then I need to use the refresh button on browser to view the new image. Curiously if i repeat the action the script starts to work fine without refresh required until new browser restart (tested in firefox and chrome).

alan
  • 1
  • I think you're saying `image.jpg` is changing and the browser should be loading that a second time, but in reality it is loading it from the cache. In that case, take a look at this: http://stackoverflow.com/questions/126772/how-to-force-a-web-browser-not-to-cache-images – ChicagoRedSox Feb 22 '14 at 19:25
  • The problem is very similar but i can't change the filename for the image. I have simplified the problem in order not to extend the question. The filename actually is a hash of a user name and the image is its avatar so must be constant. – alan Feb 23 '14 at 21:46
  • @ChicagoRedSox I beg your pardon. After closer inspection, your suggestion might work for me although i don't like it very much. It produces ungly urls ;-) – alan Feb 24 '14 at 21:53

0 Answers0