SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Zealot
    Join Date
    Jan 2005
    Location
    md
    Posts
    180
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Creating directory in PHP

    If I want to have a feature in a script that will create a directory on my server, how would this be done?

    For example, I input information (Site Name & Directory Name)

    Then it creates a directory on my server using the directory name, and also includes a file into the directory which I pre-defined..

  2. #2
    masquerading Nick's Avatar
    Join Date
    Jun 2003
    Location
    East Coast
    Posts
    2,215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    mkdir(path/name, chmod)

    Not sure about the other part of your question...
    Nick . all that we see or seem, is but a dream within a dream
    Show someone you care, send them a virtual flower.
    Good deals on men's watches

  3. #3
    SitePoint Zealot
    Join Date
    Jan 2005
    Location
    md
    Posts
    180
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a lot, thats perfect..

    What I mean as far as including a file is this..

    Right now the script im using is designed for 1 site and 1 site only.. What I would like to do is have it so that I can create a directory (which is now taken care of) but it will also insert a php page into that directory.. it will be the same page for every directory created..

    So the steps would be..

    Enter in information (directory name, site name) > create the directory > create a copy of a pre-determined file (where im at now)..


    Hope this explains it..

  4. #4
    masquerading Nick's Avatar
    Join Date
    Jun 2003
    Location
    East Coast
    Posts
    2,215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah, ok. You could use copy(). So have a single version of the file you will want to copy to each new directory, and copy it to the new directory.

    PHP Code:
    [make directory]
    copy('masterfile.php''/new-dir/file.php'); 
    Nick . all that we see or seem, is but a dream within a dream
    Show someone you care, send them a virtual flower.
    Good deals on men's watches

  5. #5
    Maniacally depressed robot poncho's Avatar
    Join Date
    Dec 2004
    Location
    Belfast, N.Ireland
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Possibility... you beauty!

    I'll also find this very handy... nice work my friend.

    PHP Code:
    $dir "";
    $masterfile "test.txt";
    if(isset(
    $_POST['dir']) && $_POST['dir'] != "") {
        
    $dir $_POST['dir'];
        
    mkdir($dir0700);
        echo 
    "Directory ".$dir."successfully created";
        
    $pathfile $dir."/".$masterfile;
        
    copy($masterfile$pathfile);
        echo 
    "File ".$masterfile."successfully copied";
    } else {
    echo 
    "There was an error of some kind...";

    Regards;
    Poncho

  6. #6
    SitePoint Zealot
    Join Date
    Jan 2005
    Location
    md
    Posts
    180
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Awsome thanks so much..

    so with your example, would the name of the file copied to the new directory be file.php? Hence it renamed masterfile.php to file.php?

  7. #7
    Maniacally depressed robot poncho's Avatar
    Join Date
    Dec 2004
    Location
    Belfast, N.Ireland
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Gexus,

    Try this code, you could set the masterfile & newfile names dynamically if you wanted, or just leave them hard-coded

    PHP Code:
    $dir "";
    $masterfile "test.txt";
    $newfile "file.php";
    if(isset(
    $_POST['dir']) && $_POST['dir'] != "") {
        
    $dir $_POST['dir'];
        
    mkdir($dir0700);
        echo 
    "Directory ".$dir."successfully created";
        
    $pathfile $dir."/".$newfile;
        
    copy($masterfile$pathfile);
        echo 
    "File ".$masterfile."successfully copied";
    } else {
    echo 
    "There was an error of some kind...";

    Perfecting the art of breaking stuff.
    Check 'em: CakePHP | TextMate

  8. #8
    masquerading Nick's Avatar
    Join Date
    Jun 2003
    Location
    East Coast
    Posts
    2,215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can name it whatever you want. If the PHP file you want copied to each dir is called "master.php", then use copy('master.php', '/new-dir/master.php');
    Nick . all that we see or seem, is but a dream within a dream
    Show someone you care, send them a virtual flower.
    Good deals on men's watches


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
  •