Jump to content


Photo

I need help making $username as a directory folder.


  • Please log in to reply
5 replies to this topic

#1 unclemid

unclemid
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 28 March 2006 - 11:25 PM

Hello Im a noob to php and was wondering how you would go about posting a variable in a directory.

Let me explain what im doing.

Im making a site with a login system ect. Im trying to make an image uploading system that uploads the pictures in the users own personal folder. and if it doesnt exist it will create it something like:

website.com/folder/folder/$username/file.jpg

my problem is getting the variable to make the folder to be made as the actual username. I am using the session thing right and everything but cant find how to fix this. Can anyone help me either find a pre-made upload system code or just tell me how to post varaibles as a directory folder. Thanks.

#2 shortj75

shortj75
  • Members
  • PipPipPip
  • Advanced Member
  • 118 posts
  • LocationPort Huron,mi

Posted 29 March 2006 - 12:09 AM

this is the code i user i dont know if it will work if your not running your own server
mkdir("C:/path/to/directory/$username") or die("Sorry I could not make the directory you requested<BR>");

and heres the code to delete the directory so you will have it just in case
rmdir("C:/path/to/directory/$username") or die("Sorry I could not delete the directory you requested<BR>");

you can try it wit a web address but if you dont run your own server you may not have the correct permissions to create directories good luck
The Short One

hopfully this helps if it doesn't sorry
i won't write the code for you!!! you don't learn that way

#3 norman100

norman100
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 29 March 2006 - 01:08 AM

[!--quoteo(post=359479:date=Mar 28 2006, 07:09 PM:name=shortj75)--][div class=\'quotetop\']QUOTE(shortj75 @ Mar 28 2006, 07:09 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
this is the code i user i dont know if it will work if your not running your own server
mkdir("C:/path/to/directory/$username") or die("Sorry I could not make the directory you requested<BR>");

and heres the code to delete the directory so you will have it just in case
rmdir("C:/path/to/directory/$username") or die("Sorry I could not delete the directory you requested<BR>");

you can try it wit a web address but if you dont run your own server you may not have the correct permissions to create directories good luck
[/quote]


I will come back and answer this for you tommorrow it can be done!!!

#4 txmedic03

txmedic03
  • Members
  • PipPipPip
  • Advanced Member
  • 313 posts
  • LocationCall, TX, USA

Posted 29 March 2006 - 07:15 AM

if (!is_dir('users/'.$username)) {
  mkdir('users/'.$username);
  chmod('users/'.$username, 0755);
}

SEMPER FIDELIS!

I can't stop you from doing something silly, but at least I can help you do it right.


#5 norman100

norman100
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 29 March 2006 - 12:09 PM

[!--quoteo(post=359568:date=Mar 29 2006, 02:15 AM:name=txmedic03)--][div class=\'quotetop\']QUOTE(txmedic03 @ Mar 29 2006, 02:15 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
if (is_dir('users/'.$username)) {
  mkdir('users/'.$username);
  chmod('users/'.$username, 0755);
}
[/quote]




Hi there

if (! is_dir($directory_path.$Code.'/'.$username))
{
mkdir($directory_path.$Code.'/'.$username);
}

//NOTE : ! before the is_dir function, if it does not exist lets create it!


//you can omit the following two lines and have newname hold the name of ur file.


//also the directory paths will need ammending

$ext=substr($_FILES['coursework']['name'], -4);

$newname=$Username.$ext;



$result = move_uploaded_file($_FILES['coursework']['tmp_name'], $directory_path.$Code.'/'.$username.'/'.$newname) ;

#6 txmedic03

txmedic03
  • Members
  • PipPipPip
  • Advanced Member
  • 313 posts
  • LocationCall, TX, USA

Posted 30 March 2006 - 12:36 AM

Thanks norman I didn't even notice I left that off.

SEMPER FIDELIS!

I can't stop you from doing something silly, but at least I can help you do it right.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users