Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

codeigniter upload encrypt_name uniqueness

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?

like image 822
Mohammad Naji Avatar asked Jul 26 '13 10:07

Mohammad Naji


1 Answers

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.

like image 102
mgrueter Avatar answered Sep 23 '22 04:09

mgrueter