1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Creating / removing folders with HTML files

Discussion in 'PHP & Perl' started by Weaxer, Dec 17, 2011.

  1. Weaxer

    Weaxer Registered Member

    Joined:
    Apr 28, 2010
    Messages:
    53
    Likes Received:
    16
    I need to create a system where my users can add pages to my host. The folders should have random names like "7b9nrer" with one index.html file in it so they can be used with for example: http://mysite.com/7b9nrer/. The index.html file should be formed from settings made by the user.

    The user should also be able to remove the pages they have created from a list of the existing pages, so I'm guessing I somehow have to combine it with SQL.

    If someone has some similar code to offer me so I can customize it myself, that would be great. I just need something to start from. Links to tutorials or anything works too. Thanks!
     
  2. wickedwebmaster

    wickedwebmaster Newbie

    Joined:
    Dec 1, 2008
    Messages:
    26
    Likes Received:
    31
    Here is example code for an image website I have. It creates a unique folder on the server and uploads a jpeg file with a unique name:

    Code:
    $jpgdata = $GLOBALS["HTTP_RAW_POST_DATA"];
      $image_id = uniqid();
      $image_dir = "./uploads/" . $image_id;
      $filename = $image_dir . "/original.jpg";
      
      mkdir($image_dir);
      file_put_contents($filename, $jpgdata);
    
     mysql_query("INSERT INTO `" . $table_prefix . "` (`id`, `uniqid`, `timestamp`) VALUES (NULL, '" . $image_id . "', CURRENT_TIMESTAMP);");
    
    Here is the code to remove the images from the database:

    Code:
    mysql_query("DELETE FROM `".$table_prefix."` WHERE uniqid = '".mysql_real_escape_string($snap_id)."'");
        
        unlink("../uploads/" . $snap_id . "/original.jpg");
        unlink("../uploads/" . $snap_id . "/thumb.jpg");
        unlink("../uploads/" . $snap_id . "/large.jpg");
        rmdir("../uploads/" . $snap_id . "/");
    
     
  3. dtang4

    dtang4 Regular Member

    Joined:
    Apr 7, 2010
    Messages:
    291
    Likes Received:
    43
    I would recommend doing everything using .htaccess and MySQL.

    For instance, have 3 tables...

    • 1 table to track your users/accounts
    • 1 table to track your folder names (mapped to the users)
    • 1 table to track your HTML files (mapped to your folders) that also contain the contents of the HTML files


    You can use .htaccess to capture all URLs ending in .html within 7-character folder name.
    e.g.
    Code:
    [a-z0-9]{7}\/.+\.html
    This will allow you to much more easily make changes across all the HTML files, since they aren't physical copies of each file.
     
  4. hypefrenzy

    hypefrenzy Junior Member

    Joined:
    Dec 12, 2011
    Messages:
    170
    Likes Received:
    19
    i recommend dropping the idea of creating actual directories/files and go with database driven php pages. too many errors happen when adding/removing directories and files. it can also become hard to manage as the amount of users increase
     
  5. wickedwebmaster

    wickedwebmaster Newbie

    Joined:
    Dec 1, 2008
    Messages:
    26
    Likes Received:
    31
    What?:confused:

    Are you just trying to boost your post count or something?