GrzegorzL
Posts: 13
|
| Posted: 04/30/2009, 11:36 AM |
|
It is a simple tool for creating a new folder with the name = user ID, for example, during registration ?
|
 |
 |
kirchaj
Posts: 215
|
| Posted: 04/30/2009, 2:17 PM |
|
GrzegorzL,
I created a function at the bottom of my common.php file
// This function is used during student registration to create the student directory using UserID
function createdir($stu_id){
// directory where student directories will be located
$root_dir = '/var/www/html/portfolio/uploads/';
$full_path = $root_dir . $stu_id;
$dir_mode = 0755;
// check to see if directory exits, if not create it
if (is_dir($full_path)==false)
mkdir ($full_path, 0755);
}
and called this function in the after_insert event on my registration page. There may be an easier way to do this but this one makes sense to me and it works like a charm.
If you have questions, let me know.
Tony
|
 |
 |
damian
Posts: 838
|
| Posted: 04/30/2009, 2:39 PM |
|
if that doesnt work for you markie has several posts on the subject if you search in here....
_________________
if you found this post useful take the time to help someone else.... :)
|
 |
 |
DonP
|
| Posted: 05/01/2009, 1:05 PM |
|
GrzegorzL wrote:
> It is a simple tool for creating a new folder with the name = user ID, for
> example, during registration ?
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.yessoftware.com/
>
Perhaps a little overly-complicated, but this is what I used on one of
my own sites. It was in an After Insert event in my user administration
form and also shows an example of inserting files into the folder and it
also modifies the .htaccess file at the same time:
global $users;
global $DBclients;
// Set session ClientID to new user
CCSetSession("ClientID", mysql_insert_id());
$ClientID = CCGetSession("ClientID");
// Create new user folders
$ServerPath = getenv("DOCUMENT_ROOT");
$FTPPath = "/public_html/domainfolder.com";
$UserName = trim(CCGetParam("FirstName", "")) .
trim(CCGetParam("LastName", ""));
//chmod($ServerPath . "/files/", 0777);
// create directory through FTP connection - be sure there are no
// spaces or other special characters in the folder name - $UserName
// variable should already have no spaces, ie: FirstLast would be the
// folder name
function FtpMkdir($path, $newDir, $permissions) {
$server='ftp.domainname.com'; // ftp server
$connection = ftp_connect($server); // connection
// login to ftp server - might be different than MySQL login
// but if not Common.php can be included here instead to put them in the
// scope of the function
$user = "FTPusername";
$pass = "FTPpassword";
$result = ftp_login($connection, $user, $pass);
// check if connection was made
if ((!$connection) || (!$result)) {
return false;
exit();
} else {
ftp_chdir($connection, $path); // go to destination dir
if(ftp_mkdir($connection, $newDir)) { // create directory
ftp_chmod($connection, $permissions, $path . $newDir); // set
permissions
return $newDir;
} else {
return false;
}
ftp_close($conn_id); // close connection
}
}
//$NewUserFolder = "/files/" . $ClientID . "-" . $UserName;
$NewUserFolder = str_replace(" ", "", $ClientID . "-" . $UserName);
FtpMkdir($FTPPath . "/files/", $NewUserFolder, 0777);
FtpMkdir($FTPPath . "/files/" . $NewUserFolder, "temp", 0777);
// Create new user default Biography and Resume entry
$SQLBio = "INSERT INTO manuscripts
(DocName,DocText,DocType,Downloadable,UserID) ".
"VALUES (". $DBclients->ToSQL('My Biography',ccsText) . ", " .
$DBclients->ToSQL('Coming soon!',ccsText) . ", ".
$DBclients->ToSQL(3,ccsInteger) . ", ". $DBclients->ToSQL(0,ccsInteger)
.. ", ". $ClientID .")";
$SQLRes = "INSERT INTO manuscripts
(DocName,DocText,DocType,Downloadable,UserID) ".
"VALUES (". $DBclients->ToSQL('My Resume',ccsText) . ", ".
$DBclients->ToSQL('Coming soon!',ccsText) . ", ".
$DBclients->ToSQL(4,ccsInteger) . ", ". $DBclients->ToSQL(0,ccsInteger)
.. ", ". $ClientID .")";
$DBclients->query($SQLBio);
$DBclients->query($SQLRes);
// Add Rewrite rule of new user name to .htaccess file
$NewHTACCESS = "RewriteRule ^". str_replace(" ", "", $UserName) ."$ http://www.domainname.com/index.php?ClientID=". $ClientID . "\r\n";
$out = fopen($ServerPath . "/.htaccess", "a");
fwrite($out, $NewHTACCESS);
fclose($out);
|
|
|
 |
GrzegorzL
Posts: 13
|
| Posted: 05/07/2009, 12:54 AM |
|
Thanks a lot
Kirchaj code sufficient for completeness.
It may be useful in the future, the also DonP code
Thanks
|
 |
 |
|