jesushax Posted March 12, 2008 Share Posted March 12, 2008 hi i have a add company form what i want to do is take the below $strCompanyName = mysql_real_escape_string($_POST["txtCompanyName"]); remove any spaces in the company name then create a sub-folder with the new company name in the below /clients/ can anyone show or point me in the right direction for these please? Thanks Link to comment https://forums.phpfreaks.com/topic/95782-remove-spaces-and-create-folder/ Share on other sites More sharing options...
unsider Posted March 12, 2008 Share Posted March 12, 2008 fopen(), and fclose() mkdir("./filename"); etc.. Google search a little bit, I'd do more to push you in the right direction, but unfortunately I've gotta get going right now. Link to comment https://forums.phpfreaks.com/topic/95782-remove-spaces-and-create-folder/#findComment-490346 Share on other sites More sharing options...
skidz Posted March 12, 2008 Share Posted March 12, 2008 $value = str_replace(' ','',$value); to remove white space and mkdir() to create directories.... www.php.net/str_replace | www.php.net/mkdir Link to comment https://forums.phpfreaks.com/topic/95782-remove-spaces-and-create-folder/#findComment-490347 Share on other sites More sharing options...
jesushax Posted March 12, 2008 Author Share Posted March 12, 2008 right heres my code i got the strign replace but the folder is not getting created in my clients folder <?php switch(@$_GET["mode"]) { case "add": include($_SERVER['DOCUMENT_ROOT'] . '/includes/header-logged.php'); include($_SERVER['DOCUMENT_ROOT'] . '/includes/connection.php'); include($_SERVER['DOCUMENT_ROOT'] . '/includes/admin_access.inc'); $strUserName = mysql_real_escape_string($_POST["txtUserName"]); $strFirstName = mysql_real_escape_string($_POST["txtFirstName"]); $strLastName = mysql_real_escape_string($_POST["txtLastName"]); $strTel = mysql_real_escape_string($_POST["txtTel"]); $strHomePage = mysql_real_escape_string($_POST["txtHomePage"]); $strCompanyName = mysql_real_escape_string($_POST["txtCompanyName"]); $strFolderPath = str_replace(' ','',$strCompanyName); $strUserPass = md5($_POST["txtUserPass"]); $strEmail = mysql_real_escape_string($_POST["txtEmail"]); $strDate = date("d/m/y"); if(!strlen($strUserName)) { echo "<p style=\"color:#FF0000;\">Error: Username Was Left Blank</p>"; } elseif(!strlen($strEmail)){ echo "<p style=\"color:#FF0000;\">Error: Email Was Left Blank</p>"; } else{ $result = mysql_query("SELECT UserName FROM tblUsers WHERE UserName='". $strUserName ."' ") or die(mysql_error()); if (mysql_num_rows($result) > 0) { echo "<p style=\"color:#FF0000;\">Error: Username Taken</p>"; } else{ mysql_query("INSERT INTO tblUsers (UserName, UserAdmin, UserPassword, UserEmail, UserCompanyName, UserCompanyFolder, UserFirstName, UserLastName, UserTel, UserHomePage, UserDateAdded) Values( '".$strUserName."','0' ,'".$strUserPass."', '".$strEmail."', '".$strCompanyName."', '".$strFolderPath."', '".$strFirstName."', '".$strLastName."', '".$strTel."', '".$strHomePage."', '".$strDate."')") or die(mysql_error()); mkdir("/clients/".$strFolderPath.""); header('Location: ?mode=done'); exit; } } break; case "done": include($_SERVER['DOCUMENT_ROOT'] . '/includes/header-logged.php'); include($_SERVER['DOCUMENT_ROOT'] . '/includes/admin_access.inc'); echo "</p>Account has been created.</p>"; break; break; default: include($_SERVER['DOCUMENT_ROOT'] . '/includes/header-logged.php'); include($_SERVER['DOCUMENT_ROOT'] . '/includes/admin_access.inc'); } include($_SERVER['DOCUMENT_ROOT'] . '/includes/nav/companies.inc'); ?> <b>Add an account</b> <form id="Profile" method="post" action="?mode=add"> <table width="100%" border="0" style="padding:0px; margin:0px;"> <tr> <td>Username: </td> <td><input type="text" name="txtUserName" size="50" /></td> </tr> <tr> <td>Password:</td> <td><input type="password" name="txtUserPass" size="25" /></td> </tr> <tr> <td>Confirm Password:</td> <td><input type="password" name="txtUserPass2" size="25" /></td> </tr> <tr> <td>Email Address:</td> <td><input type="text" name="txtEmail" size="50" /></td> </tr> <tr> <td>Company Name</td> <td><input type="text" name="txtCompanyName" size="50" /></td> </tr> <tr> <td>First Name:</td> <td><table width="100%" border="0" style="padding:0px; margin-left:-3px;"> <tr> <td><input type="text" name="txtFirstName" size="20" /></td> <td> Last Name:</td> <td><input type="text" name="txtLastName" size="20" /></td> </tr> </table></td> </tr> <tr> <td>Website Address</td> <td><input type="text" name="txtHomePage" size="50" /></td> </tr> <tr> <td>Tel: </td> <td><input type="text" name="txtTel" size="15" /></td> </tr> <tr> <td colspan="2" style="text-align:center;"><input type="submit" name="Submit" value="Add User" alt="Enter" /> <input type="Reset" name="Reset" value="Cancel" alt="Cancel" /></td> </tr> </table> </form> * a valid working email is required as your login and activation information will be sent there, thankyou. <?php include($_SERVER['DOCUMENT_ROOT'] . '/includes/footer.php'); ?> no error messages either Link to comment https://forums.phpfreaks.com/topic/95782-remove-spaces-and-create-folder/#findComment-490358 Share on other sites More sharing options...
jesushax Posted March 12, 2008 Author Share Posted March 12, 2008 can no one help? its this line thats the problem mkdir("/clients/".$strFolderPath.""); it doesnt work, is the context correct? Link to comment https://forums.phpfreaks.com/topic/95782-remove-spaces-and-create-folder/#findComment-490410 Share on other sites More sharing options...
kenrbnsn Posted March 12, 2008 Share Posted March 12, 2008 Put the echo the string to see if it is formated correctly. Why are you adding a null string on the end? <?php echo "/clients/".$strFolderPath; mkdir ("/clients/".$strFolderPath); ?> Ken Link to comment https://forums.phpfreaks.com/topic/95782-remove-spaces-and-create-folder/#findComment-490415 Share on other sites More sharing options...
jesushax Posted March 12, 2008 Author Share Posted March 12, 2008 i got /clients/testterage Warning: mkdir() [function.mkdir]: No such file or directory in /home/fhlinux153/c/cwservicesltd.co.uk/user/htdocs/admin/add_user.php on line 36s Link to comment https://forums.phpfreaks.com/topic/95782-remove-spaces-and-create-folder/#findComment-490467 Share on other sites More sharing options...
conker87 Posted March 12, 2008 Share Posted March 12, 2008 Should you be adding a trailing slash? Link to comment https://forums.phpfreaks.com/topic/95782-remove-spaces-and-create-folder/#findComment-490488 Share on other sites More sharing options...
jesushax Posted March 12, 2008 Author Share Posted March 12, 2008 been reading this http://www.w3schools.com/php/func_filesystem_mkdir.asp doesnt say how to create a subfolder dammit no trailing slashes on that either so cant tell :S Link to comment https://forums.phpfreaks.com/topic/95782-remove-spaces-and-create-folder/#findComment-490499 Share on other sites More sharing options...
skidz Posted March 12, 2008 Share Posted March 12, 2008 make sure your parent directory has 777 chmod and try setting some prams to mkdir("dir","755") for instance Link to comment https://forums.phpfreaks.com/topic/95782-remove-spaces-and-create-folder/#findComment-490514 Share on other sites More sharing options...
jesushax Posted March 12, 2008 Author Share Posted March 12, 2008 whooop like a chav in a filing cabinet.... sorted! needed document root path heres how its done for anyone else whod like to know <?php mkdir($_SERVER['DOCUMENT_ROOT'] . "/clients/".$strFolderPath); ?> Link to comment https://forums.phpfreaks.com/topic/95782-remove-spaces-and-create-folder/#findComment-490529 Share on other sites More sharing options...
conker87 Posted March 12, 2008 Share Posted March 12, 2008 Damn I was just about to suggest that! like a chav in a filing cabinet.... sorted! My work mates wonder why I actually fell off my chair then, until they read the page. Link to comment https://forums.phpfreaks.com/topic/95782-remove-spaces-and-create-folder/#findComment-490550 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.