PHP force refresh image

php

I'm creating an input form that allows users to upload an image. Once it has been submitted the user is returned to the form with a conformation bit at the top.

Any image that has been submitted is then previewed via a query to a MySQL database that stores the URL of the image. However, if the user uploads a photo, it is previewed, and then they decide to change that photo and resubmit the form, when it takes you back to the form the new photo doesn't show unless you manually press refresh on the browser.

Is there any way of forcing a refresh/cache deletion or refresh for that specific image rather than the whole page?

Thanks

Best Solution

Add the modified date to the end of the image as a query.

<img src="/images/photo.png?=1239293"/>

In PHP

<img src="/images/photo.png?=<?php echo filemtime($filename)?>"/>