Results 1 to 8 of 8

Thread: Auto Creating A File in Directory

  1. #1
    Join Date
    Dec 2010
    Posts
    30
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Thumbs up Auto Creating A File in Directory

    Hey. i want to set-up a way of creating or even moving an existing file to a directory on user login.

    For example, the user logs in and if a directory hasn't been made, its made and a few files go into it. next time the user refreshes the folder will be created and there will be some files such as index.php in there so they can get going.

    Any help would be appreciated

    Many Thanks
    Sam
    Last edited by arsenalbates; 12-28-2010 at 02:17 PM.

  2. #2
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    So do you want it to create a new directory for a user when they first log in, and then when they login after that, more files will be added?

    Here's how you can do it after a successful login, might not be exactly what you're looking for. But please explain in more detail if this isn't what you're after:

    PHP Code:
    <?php

    // For this example, I'll just set it to my username
    $username 'Schmoopy';

    // Code to authenticate login above
    // The code below assumes the user logged in successfully
    // And that the username is stored in the variable $username

    $path 'users/' $username;

    if(!
    is_dir($path)) {
        
    // If the directory does not exist, create it
        
    mkdir($path);
        
    } else {

        
    // Code to add files / refresh files here

    }

    ?>
    The code above will only handle the creating of a new directory, not creating new files within that directory.

    Please specify exactly what files you want to be put in the newly created folder.

  3. #3
    Join Date
    Dec 2010
    Posts
    30
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Wink

    Quote Originally Posted by arsenalbates View Post
    hey. I want to set-up a way of creating or even moving an existing file to a directory on user login.

    For example, the user logs in and if a directory hasn't been made, its made and a few files go into it. Next time the user refreshes the folder will be created and there will be some files such as index.php in there so they can get going.

    Any help would be appreciated

    many thanks
    sam
    solved !!!!!!

  4. #4
    Join Date
    Dec 2010
    Posts
    30
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    Thanks !

  5. #5
    Join Date
    Aug 2009
    Location
    Florida
    Posts
    23
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default

    How do you put the existing files in the directory? Let's say if you wanted to copy a file called image_upload.php and album.php ....... How would you do that?

  6. #6
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

  7. #7
    Join Date
    Aug 2009
    Location
    Florida
    Posts
    23
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default

    Nile I'm still pretty New to all this can you be a little more specific.... I followed your link and I tried to put it together myself with no luck... The directory "Schmoopy" was created, but no files were inside the directory... This is what I tried.

    PHP Code:
    <?php

    // For this example, I'll just set it to my username
    $username 'Schmoopy';

    // Code to authenticate login above
    // The code below assumes the user logged in successfully
    // And that the username is stored in the variable $username

    $path 'users/' $username;

    if(!
    is_dir($path)) {
        
    // If the directory does not exist, create it
        
    mkdir($path);

    } else {

        
    // Code to add files / refresh files here

    $file 'image_upload.php';
    $newfile 'image_upload2.php';

    if (!
    copy($file$newfile)) {
    echo 
    "failed to copy $file...n";

    }
      }
    ?>

  8. #8
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Was there a file in the root directory names image_upload2.php? I'm pretty sure you want it to upload in the Schoompy folder, correct?
    PHP Code:
    copy($file$path."/".$newfile); 
    Jeremy | jfein.net

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
  •