Welcome Guest, Not a member yet? Register   Sign In
Uploading a file, random name
#1

[eluser]donald.tbd[/eluser]
Hello, im uploading a file and trying to get a random name. The is an option $config['encrypt_name'] and when set to true it should generate a random name. My question is that is it also unique?

Looking around in forum i found that it should return something like this: md5(uniqid(mt_rand())) (not sure if correct info) but in that case as i understand uniqid is something based on time and mt_rand is a totally random number so can i safely assume that using this function two files wont be uploaded with the same name?

Thanks.
#2

[eluser]donald.tbd[/eluser]
Would be greatful if anyone could anwser Smile
#3

[eluser]InsiteFX[/eluser]
Add a datetime stamp to your file name then it will be unique!

Code:
$this->load->helper('date');

$filename = $filename.now();

[raw_name].now().[file_ext];

You will have to play with it to get the extension etc, but should
give you a unique filename.

#4

[eluser]donald.tbd[/eluser]
looked it up in the code:
$filename = md5(uniqid(mt_rand())).$this->file_ext;

Doesn't uniqid() already give me a value based on current time? that + mt_rand should be unique already?

Or am i missing something? if so then ill just have to add now() right to that function although i don't prefer changing core files.




Theme © iAndrew 2016 - Forum software by © MyBB