Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question about uploading files.

Status
Not open for further replies.

kjspear

Programmer
Joined
Feb 13, 2002
Messages
173
Location
US
Hello everyone!

I have a question. I have a form that the user can use to upload their image files to a server. Which works fine.

What I failed to discover before was what if someone uploads a file that happens to have the same name that's already in the upload directory on the server?

I'm trying to avoid these files from being overwritten in the directory because they may have the same file name.

I'd rather avoid use the file exist() function due to the excessive usage of memory.

What I would like to do instead is have php attach a random ID to the begining of the file name.

(ie 'image.gif changed to r3j2image.gif)

Simply let the random function add this to the file name before it is uploaded. I guess what I'm doing is renaming the file.

This way the files are less likely to be overwritten in the directory.

Any suggestions?

Thanks
KJ
 
O.K., sorry if I wasn't clear. Basically what is the correct
syntax for attaching the random characters to the begining of the file name?

After the user selects his/her file from there computer via form, is there a way to attach or concatenate both the random string and the file name to make up a new file name?

(i.e. random characters which was generated by php,

'r842'+ the filename 'image.gif', to read and upload as 'r842image.gif'.

Thanks,
KJ
 
random is a little vague tho, you could use yearmonthday at least for uniqueness.
Code:
<?php
$name=&quot;test&quot;;
$now=date(&quot;ymd&quot;);
$newname=$now.$name;
echo $newname;
?>

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
That'd just be plain St00pid tho .. :-)

As I always say, you can work towards combating stupidity, but if you succeed too well, you will breed idiots.

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top