wrathican Posted December 22, 2006 Share Posted December 22, 2006 hey i have a problem with a register script.what i want to happen is when a user submits their information and the registration is successful, a directory under their name is created in a specific location. i assume you can do this using a if statement. so i have created the following one:[code]$userdir=$_POST['user'];if($q=success){mkdir("/htdocs/images/gallery/".$userdir, 0777);}[/code]if your wondering what $q is, its this:[code]$q = "INSERT INTO users VALUES ('$username', '$password')";[/code]when i load up the page i get this warning:[quote]Warning: mkdir(): open_basedir restriction in effect. File(/htdocs/images/gallery/) is not within the allowed path(s): (/tmp:/usr/share/pear:/home/fhlinux178/g/gallery.ls12style.co.uk/user) in /home/fhlinux178/g/gallery.ls12style.co.uk/user/htdocs/register.php on line 34[/quote]your help is greatly appreciated Quote Link to comment https://forums.phpfreaks.com/topic/31577-if-statement-and-mkdir-within-luser-register-script/ Share on other sites More sharing options...
HuggieBear Posted December 22, 2006 Share Posted December 22, 2006 This means that your host has a restriction in place to only allow writing in certain directories.You should be able to contact your host to find out where you can create directories.Look [url=http://uk2.php.net/features.safe-mode]here[/url] for further detailsRegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/31577-if-statement-and-mkdir-within-luser-register-script/#findComment-146348 Share on other sites More sharing options...
trq Posted December 22, 2006 Share Posted December 22, 2006 You might try...[code=php:0]mkdir($_SERVER['DOCUMENT_ROOT']."/images/gallery/".$userdir, 0777);[/code]/htdocs doesn't look right. Quote Link to comment https://forums.phpfreaks.com/topic/31577-if-statement-and-mkdir-within-luser-register-script/#findComment-146349 Share on other sites More sharing options...
wrathican Posted December 22, 2006 Author Share Posted December 22, 2006 hey thorpe thanksthe code you suggested definately did something right.the error message has changed from the above to this:[quote]Warning: mkdir(/home/fhlinux178/g/gallery.ls12style.co.uk/user/htdocs/images/gallery/): File exists in /home/fhlinux178/g/gallery.ls12style.co.uk/user/htdocs/register.php on line 34[/quote] Quote Link to comment https://forums.phpfreaks.com/topic/31577-if-statement-and-mkdir-within-luser-register-script/#findComment-146351 Share on other sites More sharing options...
wrathican Posted December 22, 2006 Author Share Posted December 22, 2006 well i have figured out why i get that error message. its because the initial directories have already been created. when running the script it creates the folder that i want, but it still displays the error. ??? >:(i want it so that it doesnt display the error.another problem is that from testing it when i come to clean up the mess i made, i cannot delete the folders because i didnt create them. the script did. does this mean i have to use a script to delete them? Quote Link to comment https://forums.phpfreaks.com/topic/31577-if-statement-and-mkdir-within-luser-register-script/#findComment-146450 Share on other sites More sharing options...
craygo Posted December 22, 2006 Share Posted December 22, 2006 use file_exists() to check and see if the folder exists first before you create it.[code]<?phpif(!file_exists($folder)){mkdir($_SERVER['DOCUMENT_ROOT']."/images/gallery/".$userdir, 0777);} else {echo "Folder already exists";}?>[/code]Ray Quote Link to comment https://forums.phpfreaks.com/topic/31577-if-statement-and-mkdir-within-luser-register-script/#findComment-146452 Share on other sites More sharing options...
wrathican Posted December 24, 2006 Author Share Posted December 24, 2006 hey ray, thanks for your help, but that is not my problem.if i am reading that code right, it is only creating the directory if it doesnt exist in the first place.but what i want is a piece of code that creates a folder in that directory everytime a user registers with my website.but only if the registration is sucessful.would i be better off sending the variable to another php file in that directory with the mk dir function? Quote Link to comment https://forums.phpfreaks.com/topic/31577-if-statement-and-mkdir-within-luser-register-script/#findComment-147376 Share on other sites More sharing options...
Stooney Posted December 24, 2006 Share Posted December 24, 2006 I happen to be working on a site that does just what you want. I'll go ahead a post a piece of my registration script, it's 100% working.also note that there's no implemented security such as add_slashes() and whatnot, don't forget to add that.func.php[code]function set_dir($user){ $path="users"; $newdir="$path/$user"; mkdir($newdir, 0777);}function register_new($username, $password, $passwordb, $email, $terms){ $check=@mysql_query("select username, email from filehost_users"); while($row=mysql_fetch_array($check)) { if($row[0]==$username) { $regp=1; $_SESSION['error'].="<p>That username is already taken.</p>"; } if($row[1]==$email) { $regp=1; $_SESSION['error'].="<p>That email is already in use by another account.</p>"; } } if(!$username) { $regp=1; $_SESSION['error'].="<p>You must specify a username.</p>"; } if(!$password) { $regp=1; $_SESSION['error'].="<p>You must enter a password.</p>"; } if(!$email) { $regp=1; $_SESSION['error'].="<p>You must enter an email address.</p>"; } if($password != $passwordb) { $regp=1; $_SESSION['error'].="<p>The passwords entered do not match.</p>"; } if(!$terms) { $regp=1; $_SESSION['error'].="<p>You must agree to the Terms & Conditions.</p>"; } if($regp==1) { header("Location: $_SESSION[url]?loc=register"); exit(); } $register=@mysql_query("insert into filehost_users (username, password, email) values ('$username', PASSWORD('$password'), '$email')"); set_dir($username); return $register;}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/31577-if-statement-and-mkdir-within-luser-register-script/#findComment-147380 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.