Jump to content


Photo

Renaming a file whilst uploading, cant get the mime type to work


  • Please log in to reply
5 replies to this topic

#1 echoninja

echoninja
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 03 March 2006 - 07:25 AM

Hi again folks, I have an upload script for avatars/images, but I dont want them to retain their original name I want them to use the session id, now I can get the files to upload with the session ID but I cant get the extension to go on, any help?
I have currently:

$ext = $_FILES['avatar']['type'];
if (move_uploaded_file($_FILES['avatar']['tmp_name'],$upload_dir.session_id() .".". $ext)) {


#2 heckenschutze

heckenschutze
  • Members
  • PipPipPip
  • Advanced Member
  • 257 posts
  • LocationAustralia

Posted 03 March 2006 - 09:04 AM

why are you renaming the files to session id?

Perhaps a timestamp is better, mainly because if you use that session_id later, the image will be overwritten.

#3 echoninja

echoninja
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 03 March 2006 - 09:26 AM

because its for user avatars, and session id's are unique. That's not important though, I cant get the mime type to add onto the end

#4 echoninja

echoninja
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 03 March 2006 - 10:11 AM

nevermind i actually found it in the membership tutorial, well the command, then used it for my own diabolical ends :) if anyone wants to know

$ext = strrchr($_FILES['avatar']['name'], ".");
if (move_uploaded_file($_FILES['avatar']['tmp_name'],$upload_dir.session_id() .".". $ext)) {


#5 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 03 March 2006 - 02:13 PM

I would still re-consider ussing the session id in teh file name. Remeber these are generated randomly - they ARE NOT unique to each user - each time you login in the seesion id will in 9 zillion cases be different to the last session id you had.

Now if you set a session variable called ID and set that to the unique identifier for the user form your database - that would be a different matter and your system would then work.
follow me on twitter @PHPsycho

#6 echoninja

echoninja
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 04 March 2006 - 01:18 AM

I acutally decided (before reading your post) to inster $username at the start, so then it doesn't matter if they overwrite a file, because they are changing it for their avatar anyways. Thanks for the help folks




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users