Creating Directory With Php Script Via Website

liunx

Guest
I've been working on a little site for some sig hosting for a website i staff at.<br /><br />What i've been trying to figure out is this. I know to make a directory with php, i need to do mkdir("path",permissions). But so far its not working for me <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/sad.gif" style="vertical-align:middle" emoid=":(" border="0" alt="sad.gif" /> <br /><br />What i was trying to do was whenever a user created an account, there would be a folder created in a certain location /public_html/website_dir/users_images/here<br /><br />but i guess i'm missing something, since so far i've had no luck. <br /><br />I've tried doing the /home/account/public_html/website_dir..... and nothing happened. Is there something i'm missing in regards to the servers here? or maybe my .htaccess or php.ini files or maybe folder permissions perhaps? Any help would be greatly appreciated. Thanks!<!--content-->
well, i found a way to create a folder, not sure if i'll be able to upload to it, but i'm hopefull. =) Instead of using the mkdir command I created it via ftp (as in coding the ftp stuff on the page so its automatic). while browsing forums and such, i saw that other people had to use this format to do what i was trying to do due to security settings or somethign i think. So I think i'm all good. But still wondering exactly how to do this using the php only method (not having to use ftp). Oooooh well. =)<!--content-->
You'd need to setup the CHMOD settings correctly to allow the script the access to the folder to create subdirectories in it...<br /><br />755, right fellas? I keep forgetting what the CHMOD settings are...<!--content-->
i've been somewhat successful with my uploading of images, but only if the destination directory is chmod 777. <br /><br />Also, I try to chmod() the directory after i create it within my php code and get this error message<br /><br /><b>Warning: chmod(): Operation not permitted in /home/username/public_html/hosting/new_account.php on line 150</b><br /><br />using the ftp commands, i'm able to easily create the directories that i was needing, no problems, just cant change the mode without manually ftping into my account and doing it that way. Also, hosting and new_account directories are both set to mode 777.<br /><br /><br /><br />heres the code that is doing that the directory creation, etc...<br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->$connection = ftp_connect(my_domain');<br />$ftp_username = 'my_login';<br />$pass = 'my_password';<br />$login_result = ftp_login($connection,$ftp_username,$pass);<br /><br />// check to make sure you're connected:<br />if ((!($login_result)) or (!($connection)))<br />{<br /> // error....do something <br />}<br />else<br />{<br /> // we're good to go -- the connection was made<br /> ftp_chdir($connection,'/public_html/hosting/user_images/');<br /> ftp_mkdir($connection,$username);<br /> <br />//do this since cant use ftp_chmod (version 5.x only) is the path correct?<br />$chmodpath = "/home/username/public_html/hosting/user_images/$username";<br /> chmod($chmodpath,0777);<br /><br /> ftp_close($connection);<br />}<!--c2--></div><!--ec2--><br /><br />if one of you guys has any ideas, i'm definately open to input and suggestions, this has got my stumped. Maybe i'm just not seeing something that i should? Thanks.<!--content-->
Hey, TCH staff!<br />I wanted to know about this myself: <br /><br /><!--quoteo--><div class='quotetop'>QUOTE</div><div class='quotemain'><!--quotec-->while browsing forums and such, i saw that other people had to use this format to do what i was trying to do due to security settings or somethign i think. <!--QuoteEnd--></div><!--QuoteEEnd--><br /><br />Is it true that using php's mkdir() and/or copy() functions are not doable on TCH hosted directories, as Shannon suggests above? I was hoping to write a little automated script for my own site that would copy files from one directory, create a new dir, and paste the files in the new dir. <br />Would we have to use php ftp commands instead, as Shannon has done?<br />Thanks!<!--content-->
I'm not very familiar with directory functions within PHP...<br /><br />You might want to take a look at PHP's umask() function on the php.net website.<!--content-->
The main thing to remember is that PHP scripts used as your webpages run as the user of the webserver (user "nobody"), not as your account. So you have to make sure that the user "nobody" can do what it needs to do, which usually involves world access rights.<br /><br />For example, if you have a directory called "test" owned by you that has permissions 755 - world has read and execute (listing) permissions - and you access the following PHP script within it:<br /><br /><!--fonto:courier--><span style="font-family:courier"><!--/fonto--><?php<br />mkdir("phpmade",0755);<br />?><!--fontc--></span><!--/fontc--><br /><br />You will get a permission denied. If you change the permissions on "test" to 777 (so world has write access), you will get a directory like as follows:<br /><br /><!--fonto:courier--><span style="font-family:courier"><!--/fonto-->drwxr-xr-x 2 nobody nobody 4096 Apr 12 00:37 phpmade<!--fontc--></span><!--/fontc--><br /><br />As you'll notice, it's owned by the user nobody because the webserver created it via your PHP script. To then upload files to that directory via PHP, you don't need 777 permission on THAT directory because the webserver is the owner (but you WILL have to change it to 777 or at least 757 in order for you yourself to write to the directory).<br /><br />If you let PHP create directories for you, just keep in mind you will have to deal with directories that aren't owned by you, and you can't change the owner of (only the permissions). The exception to that would be any PHP scripts you run from the command line (such as a cron job, not a web based page).<!--content-->
thanks for the feedback. After reading countless informational topics i realized what you guys were talking about. This was the first time i'd really got into the file system functions that php can use, so it was a learning experience, but i did get it to do exactly like i needed.<br /><br />Your last example MikeJ really cleared the air though. Thanks.<!--content-->
 
Top