CodeIgniter Forums
When I refresh the page it duplicates a image - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: When I refresh the page it duplicates a image (/showthread.php?tid=84994)



When I refresh the page it duplicates a image - AlfredinhoRamses91 - 12-01-2022

Hello everybody. 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, Alfredinho.


RE: When I refresh the page it duplicates a image - captain-sensible - 12-04-2022

on my webs , only admin can log in so it should be fairly foolproof ...however
i use a form to upload an image

i get data on image name such as ..
Code:
$file = $this->request->getFile('userfile');
                   $name= $file->getName();
                $tempfile = $file->getTempName();
                $slug= url_title($cleanTitle);

but before any image can be uploaded i do a check on directory where irt would go, using variations on:

Code:
file_exists(nameOfImage)

So if there was refresh or any circumstance where there was an attempt to load same image, it would feedback "image already exists" so it would do that before
any image was uploaded