Page 1 of 3 123 LastLast
Results 1 to 10 of 23

Thread: On register create new directory and copy files

  1. #1
    Join Date
    Oct 2006
    Posts
    183
    Thanks
    0
    Thanked 11 Times in 11 Posts

    Default On register create new directory and copy files

    Does anyone know of a script where people cna register and when they do it makes a new directory and copies folders from another directory over to the directory they just made?

    I want it to copy them over, but then make them separate so they don't edit it and it edits the original directory too.

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    To make the new directories you could simply use the mkdir(); function that PHP has. As far as coping folders over, I'm not sure I quite follow you. Does the user already have the folders on the server somewhere, then you just want to copy the files from there to the new directory? If so, you could also use the copy(); function. Let me know if this helps or not.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    Oct 2006
    Posts
    183
    Thanks
    0
    Thanked 11 Times in 11 Posts

    Default

    i dont know how to use either of those functions, I haven't usd either before...

    I have heard of mkdir though...

    the copy thing, I want to put files on a folder somewhere on my site, then when the user registers it will copy the files from the hidden folder and then disconnect, therfore when you edit files in the new directory, it doesn't edit both the new directory AND the directory they were copied from...

  4. #4
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Ok then lets just use the following (non-tested) code as an example. Edit the following as needed.

    PHP Code:
    <?php
    //Start Config

    $homepath "/home/mysite/public_html/members/"
    $filesdir "/home/mysite/hidden/";

    //for windows systems, uncomment the following and comment above.
    //$homepath = "C:/mysite/www/members/";
    //$filesdir = "C:/mysite/hidden/";

    /* Add the files in which you want to copy from the old to the new directory. Use the same format as below! */

    $cpFiles = array("file1.txt","file2.png","file3.php","file4.dat");

    // End config
    reset($cpFiles);

    $username $_REQUEST["username"];
    $userDir $homepath.$username;

    //create the new directory
    $newDir mkdir($userDir0777);


    if (!
    $newDir) {

    //If directory not created, end script and display error message

    exit("The user directry was not created. Please try again or contact an Administrator.");

    }

    else {

    //Begin copying files listed in the cpFiles array to the new directory.

    foreach($cpFiles as $theFile) {

    copy($filesdir.$theFile,$userDir.$theFile);

    //end foreach


    //end else

    ?>
    Please note, that the directory that the ones will be created in must be chmod to 777 or all writeable. Let me know if you need any further help.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  5. #5
    Join Date
    Oct 2006
    Posts
    183
    Thanks
    0
    Thanked 11 Times in 11 Posts

    Default

    in the

    Code:
    /* Add the files in which you want to copy from the old to the new directory. Use the same format as below! */
    
    $cpFiles = array("file1.txt","file2.png","file3.php","file4.dat");
    what if I want it to copy all files?

    If I want all files from the directory "http://site.com/dir/test/" to copy to "http://site/directoryname/*here are all the files*"

    would I make the script as copying from "http://site.com/dir/" and then the cpfiles array as "test/"?

    then it would be like
    Code:
    $homepath = "http://site.com/dir"; 
    $filesdir = "http://site.com/directoryname/";
    
    /* Add the files in which you want to copy from the old to the new directory. Use the same format as below! */
    
    $cpFiles = array("test/");

  6. #6
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    if you wanted to copy all the files, try the following:

    PHP Code:
    <?php
    //Start Config

    $homepath "/home/mysite/public_html/members/"
    $filesdir "/home/mysite/hidden/";

    //for windows systems, uncomment the following and comment above.
    //$homepath = "C:/mysite/www/members/";
    //$filesdir = "C:/mysite/hidden/";

    // End config

     
    if ($dir opendir($filesdir)) {
     
    while (
    false !== ($file readdir($dir)))
         {

    if (
    $file != "." && $file != "..") {
          
    if (
    is_file($file)) {  

    $cpFiles[] = $file;

    }
    }

    //end while

    reset($theFiles);


    $username $_REQUEST["username"];
    $userDir $homepath.$username;

    //create the new directory
    $newDir mkdir($userDir0777);


    if (!
    $newDir) {

    //If directory not created, end script and display error message

    exit("The user directry was not created. Please try again or contact an Administrator.");

    }

    else {

    //Begin copying files listed in the cpFiles array to the new directory.

    foreach($cpFiles as $theFile) {

    copy($filesdir.$theFile,$userDir.$theFile);

    //end foreach


    //end else

    ?>
    Note this will only take files (not directories) in the hidden folder you want to be copied over. That should get you started at least. Also note, that the $homepath and $filesdir variables are absolute paths to the folders, not relative. In other words, where on your server, are the items located? I'm not sure if this is the correct terms for the paths, but it would be "/home/sites/mysite/www/index.php" (or for windows using IIS: "c:/Inetpub/www/index.php") instead of "http://mysite.com/index.php" if that makes sense.

    Again let me know if you need any further help.
    Last edited by thetestingsite; 11-25-2006 at 04:49 AM. Reason: Did not finish the rest of the post.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  7. #7
    Join Date
    Oct 2006
    Posts
    183
    Thanks
    0
    Thanked 11 Times in 11 Posts

    Default

    o like when i get errors how it will have like /var/something/morestuff/file.php is what i use?

  8. #8
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    exactly.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  9. #9
    Join Date
    Oct 2006
    Posts
    183
    Thanks
    0
    Thanked 11 Times in 11 Posts

    Default

    okay so basically to find out I should make a page that has an error and copy the one that is there?

    If there is some way to get it in like the web hosting area I can't because I am only 14 and my site is a sub domain on my dad's site... so the error one will work, right? if not I can't find it out through the hoster...

  10. #10
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    you could do it that way, or you could find out by putting this in a php page.

    PHP Code:
    <?php
    echo getcwd();

    /* 

    will produce something like /home/public_html/myfolder/ or C:/www/myfolder/ 

    */
    ?>
    Other than that, if you have any problems let me know. Or if you would like, I could set you up a subdomain on one of my websites, for testing purposes.
    Last edited by thetestingsite; 11-25-2006 at 08:41 PM. Reason: forgot to close php tag
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •