PHP File upload - rename file

This is a discussion on PHP File upload - rename file within the PHP Language forums, part of the PHP Programming Forums category; Hi, I have to allow my visitors to upload image on my site. I am using the follwoing code to ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 12-14-2004
smilesinblues@hotpop.com
 
Posts: n/a
Default PHP File upload - rename file

Hi,
I have to allow my visitors to upload image on my site.

I am using the follwoing code to do that:

$uploaddir = 'admin/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile);

My problem is that I expect them to use same file name, like all of
them will be uploading files like, comments.rtf. So if there is already
one comments.rtf the file will get overwriten... so the challenge is to
rename the files to username-filename.rtf

can anybody here will take the pain to modify this code, I will be
thankful, or please guide to me some tutorial where they are dealing
with simple code and not with advanced classes.
Thank you in advane

Regards,
Jaunty Edward

Reply With Quote
  #2 (permalink)  
Old 12-14-2004
Geoff Berrow
 
Posts: n/a
Default Re: PHP File upload - rename file

I noticed that Message-ID:
<1103007641.349701.201220@f14g2000cwb.googlegroups .com> from
smilesinblues@hotpop.com contained the following:

>
>$uploaddir = 'admin/';
>$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
>move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile);
>
>My problem is that I expect them to use same file name, like all of
>them will be uploading files like, comments.rtf. So if there is already
>one comments.rtf the file will get overwriten... so the challenge is to
>rename the files to username-filename.rtf


Is the username unique? If so it's just

$uploadfile = $uploaddir.
$username.basename($_FILES['userfile']['name']);

Though you might like to add a character for neatness

$uploadfile = $uploaddir .
$username."-".basename($_FILES['userfile']['name']);



--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Reply With Quote
  #3 (permalink)  
Old 12-15-2004
smilesinblues@hotpop.com
 
Posts: n/a
Default Re: PHP File upload - rename file

Hi,
thank you so much Geoff Berrow its worked infact now I can use many
ways to changing name of file.

Thank you.

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 09:16 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0