Jump to content

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


echoninja

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]
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]
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.

Archived

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

×
×
  • Create New...

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.