CodeIgniter Forums
How to avoid duplicate uploaded file? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: How to avoid duplicate uploaded file? (/showthread.php?tid=52373)



How to avoid duplicate uploaded file? - El Forum - 06-07-2012

[eluser]solid9[/eluser]
Hi guys

I want to avoid duplicate uploaded file names.
But what CI did was it duplicate the name and extended
the name with numbers like this below,

Code:
android.jpg
android1.jpg
android2.jpg
android3.jpg
and so on...

How to avoid this duplicate files but instead just replace the
existing the same file with new file?

Thanks in advanced.







How to avoid duplicate uploaded file? - El Forum - 06-07-2012

[eluser]Abel A.[/eluser]
Get the hash value of the file and compare it to other hashes. Each file has a unique hash and if they're identical files, then they will have the same hash value.

It is not optimal to check every single file's hash value from the hdd, but instead have the hash values stored in the database.

Use md5 to get the hash value.

http://php.net/manual/en/function.hash-file.php


How to avoid duplicate uploaded file? - El Forum - 06-08-2012

[eluser]LuckyFella73[/eluser]
According to the userguide you need that config item:
Code:
$config['overwrite'] = TRUE;