CodeIgniter Forums

Full Version: Refresh the page duplicates a image uploaded
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello, all.

I am a new user of CodeIgniter and I am having a problem after uploading a image.
I need to upload a file and everything is fine. After I upload the file I get redirected to a success page. But if I refresh (F5) this page, the image is duplicated in the folder.
As I am renaming it, it never will get the same name, so I can not "override" the image.

I have already tried to "unset($imageUploaded)" after I upload it, but it did not worked.

Anyone has any idea abut how to solve this problem?

Thanks,

Luis.
Refreshing is resubmitting the original form data from the browser's cache (most browsers will even prompt you about this). Since PHP (and, by extension, CodeIgniter) is on the server and basically starts over from the beginning for each request, there are only a few ways to tell the difference between a refreshed page and a completely new request.

You could set some session data (file name and size, depending on how careful you want to be) and prompt the user if they appear to be uploading the same file. You could even prevent them from uploading another file for a set period of time, though in some cases this will just be frustrating for users.
Seems there is something wrong with your redirecting method. If you apply this correctly, the url changes and there is no reference to your upload form anymore. Refreshing the success page should not result in uploading a file again.
So please check if the url of the success page is not the same as your upload form.