Jump to content

Archived

This topic is now archived and is closed to further replies.

echoninja

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

Recommended Posts

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:

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.