Search code examples
phpimageapachecachingfile-upload

showing old image even after new image is being uploaded


I'm uploading file using php and displaying it as soon as uploading competed. Sometimes it shows old image, doesn't showing newly uploaded. but hitting refresh will display new image. How can I get rid of this? I'm using apache web server.


Solution

  • it is due to browser's cache. Try to add a random number in filename path, e.g.

    <img src="image.jpg?rand=<?php echo rand(); ?>" />
    

    of course, the rand is generated by random function ( PHP / Javascript ) each time.