Jump to content

Archived

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

unclemid

I need help making $username as a directory folder.

Recommended Posts

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.

Share this post


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

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

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

Share this post


Link to post
Share on other sites
[!--quoteo(post=359479:date=Mar 28 2006, 07:09 PM:name=shortj75)--][div class=\'quotetop\']QUOTE(shortj75 @ Mar 28 2006, 07:09 PM) [snapback]359479[/snapback][/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
[code]
mkdir("C:/path/to/directory/$username") or die("Sorry I could not make the directory you requested<BR>");
[/code]

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

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!!!

Share this post


Link to post
Share on other sites
[code]if (!is_dir('users/'.$username)) {
  mkdir('users/'.$username);
  chmod('users/'.$username, 0755);
}[/code]

Share this post


Link to post
Share on other sites
[!--quoteo(post=359568:date=Mar 29 2006, 02:15 AM:name=txmedic03)--][div class=\'quotetop\']QUOTE(txmedic03 @ Mar 29 2006, 02:15 AM) [snapback]359568[/snapback][/div][div class=\'quotemain\'][!--quotec--]
[code]if (is_dir('users/'.$username)) {
  mkdir('users/'.$username);
  chmod('users/'.$username, 0755);
}[/code]
[/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) ;

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.