Hi
My site allows users to upload a number of images to the web server. What I would like to do is generate a unique filename for each file uploaded so as I don't have the problem of 2 or more users uploading an image with the same name.
Is there a function to achieve this?
Thanks in advance
generating a unique file name
Moderator: General Moderators
- dibyendrah
- Forum Contributor
- Posts: 491
- Joined: Wed Oct 19, 2005 5:14 am
- Location: Nepal
- Contact:
Simple solution
Code: Select all
$unique_output_file_name = md5(microtime()) . ".jpg";dibyendrah wrote:Simple solutionCode: Select all
$unique_output_file_name = md5(microtime()) . ".jpg";
Code: Select all
$unique_output_file_name = md5(microtime()) . ".jpg";
//just in case
while (file_exists($unique_output_file_name)) {
$unique_output_file_name = md5(microtime()) . ".jpg";
}
echo $unique_output_file_name;