unclemid Posted March 28, 2006 Share Posted March 28, 2006 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.jpgmy 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. Quote Link to comment https://forums.phpfreaks.com/topic/6051-i-need-help-making-username-as-a-directory-folder/ Share on other sites More sharing options...
shortj75 Posted March 29, 2006 Share Posted March 29, 2006 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 Link to comment https://forums.phpfreaks.com/topic/6051-i-need-help-making-username-as-a-directory-folder/#findComment-21771 Share on other sites More sharing options...
norman100 Posted March 29, 2006 Share Posted March 29, 2006 [!--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!!! Quote Link to comment https://forums.phpfreaks.com/topic/6051-i-need-help-making-username-as-a-directory-folder/#findComment-21792 Share on other sites More sharing options...
txmedic03 Posted March 29, 2006 Share Posted March 29, 2006 [code]if (!is_dir('users/'.$username)) { mkdir('users/'.$username); chmod('users/'.$username, 0755);}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/6051-i-need-help-making-username-as-a-directory-folder/#findComment-21859 Share on other sites More sharing options...
norman100 Posted March 29, 2006 Share Posted March 29, 2006 [!--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) ; Quote Link to comment https://forums.phpfreaks.com/topic/6051-i-need-help-making-username-as-a-directory-folder/#findComment-21911 Share on other sites More sharing options...
txmedic03 Posted March 30, 2006 Share Posted March 30, 2006 Thanks norman I didn't even notice I left that off. Quote Link to comment https://forums.phpfreaks.com/topic/6051-i-need-help-making-username-as-a-directory-folder/#findComment-22141 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.