December 2nd, 2012, 09:23 AM
Uploading file with automated random genertaed names
I am a beginner so I need your guys help in the following simple code i.e,
$uploaddir = "profilepictures";
print "Your picture has been uploaded successfully!";
i want to use the 'rand' command but i dont know where to add that in the above code so kindly please help me,thanks...
December 2nd, 2012, 09:49 AM
You need to replace $_FILES['file']['name'] with something that generates a random file name. For example, the uniqid() function.
Although ideally you need to run some checks to make sure the file doesn't already exist in the directory, otherwise you'll overwrite it.
move_uploaded_file($_FILES['file']['tmp_name'],$uploaddir.'/'. uniqid() . '.jpg');
If you change the '.jpeg' part to anything other than a static extension then you need to perform validation of the extension against a whitelist.
December 2nd, 2012, 09:58 AM
Hey thanks alot buddy, i really appreciate it!
Originally Posted by E-Oreo
December 2nd, 2012, 10:34 AM
hey can you also tell me how to insert the uniqid generated into database simultaneously,thanks