5

1. Does codeigniter's upload library's encrypt_name option check to be unique?

I know that the overwrite option is important. If overwrite is TRUE, it would overwrite and if it's FALSE, it would rename the file by adding a number at the end of the name.

The question is: Will it regenerate the encrypted name until finding a unique name even if overwrite is TRUE? I ask this because it's obvious that when we want encrypted name, of course we don't want to overwrite.

The problem with rename by adding some numbers is that it corrupts the size of file names. Many files will have 32 chars filename, and some might have 33 chars filename that corrupts coordination.

2. Is that possible to generate an ever-duplicated result at all?

Mohammad Naji
  • 5,372
  • 10
  • 54
  • 79
  • If `overwrite` is set to `true` then the encoded name if matched with an existing file will replace the earlier file else it will rename the current uploaded file. – Nil'z Jul 26 '13 at 10:16
  • Sorry, sorry, I meant even if overwrite if `FALSE`. Edited the q. Thank you for your note. – Mohammad Naji Jul 26 '13 at 10:19
  • Yes, even it matches a file that is already uploaded which is next to impossible it will rename the file that is being uploaded. – Nil'z Jul 26 '13 at 10:21
  • I was right, but I hadn't given enough information! Updated and explained the challenges in my mind. Thank you `Niloy` for forcing me to explain! `:)` – Mohammad Naji Jul 26 '13 at 10:37

1 Answers1

6

Since Codeigniter is using md5(uniqid(mt_rand())) to generate the encrypted file name, I'd guess that you'll find your answer in the PHP docs for uniquid.

Short answer (for 2.) would be: maybe, but probably not.

And to answer your first question: no, CI doesn't generate a new encrypted filename, if it already exists. It adds a number to the end of the name.

A short glance at the source code of /libraries/Upload.php, line 415, helps.

mgrueter
  • 1,400
  • 6
  • 15