echoninja Posted March 3, 2006 Share Posted March 3, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/3983-renaming-a-file-whilst-uploading-cant-get-the-mime-type-to-work/ Share on other sites More sharing options...
heckenschutze Posted March 3, 2006 Share Posted March 3, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/3983-renaming-a-file-whilst-uploading-cant-get-the-mime-type-to-work/#findComment-13849 Share on other sites More sharing options...
echoninja Posted March 3, 2006 Author Share Posted March 3, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/3983-renaming-a-file-whilst-uploading-cant-get-the-mime-type-to-work/#findComment-13852 Share on other sites More sharing options...
echoninja Posted March 3, 2006 Author Share Posted March 3, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/3983-renaming-a-file-whilst-uploading-cant-get-the-mime-type-to-work/#findComment-13864 Share on other sites More sharing options...
ToonMariner Posted March 3, 2006 Share Posted March 3, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/3983-renaming-a-file-whilst-uploading-cant-get-the-mime-type-to-work/#findComment-13906 Share on other sites More sharing options...
echoninja Posted March 4, 2006 Author Share Posted March 4, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/3983-renaming-a-file-whilst-uploading-cant-get-the-mime-type-to-work/#findComment-14046 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.