Create new folder & add file template in php?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Publisher Bucks
    Confirmed User
    • Oct 2018
    • 1330

    #1

    Tech Create new folder & add file template in php?

    I'm currently trying to get a part of an admin system setup whereby I can create a new sub directory on a domain, I have that part working however, I'm having issues putting a .php template into the directory once it has been created.

    Here is the code I'm using to create the directory itself on the server:

    <?php
    function createDirectory() {
    $add = $_POST["add"];
    mkdir("/blah/blah/domain.com/toplevel".$add);
    echo "<script type = 'text/javascript'>alert('Done!');</script>";
    }
    ?>
    <html>
    <head>
    <base href="https://gfy.com/" /><!--[if IE]></base><![endif]-->
    <title>
    Create directory
    </title>
    </head>

    <body>
    <?php
    if (!isset($_POST['submit'])) {
    ?>
    <form action = "" method = "post">

    <table>
    <tr>
    <td style = " border-style: none;"></td>
    <td bgcolor = "blue" style = "font-weight: bold">
    Directory Name
    </td>

    <td bgcolor = "red">
    <input type = "text" style = "width: 220px;"
    class = "form-control" name = "add" id = "add" />
    </td>

    <td bgcolor = "blue" colspan = "2">
    <input type = "submit" name = "submit"
    value = "Create directory" />
    </td>
    </tr>
    </table>
    </form>
    <?php
    }
    else {
    createDirectory();
    }
    ?>
    </body>
    </html>
    Like i say, the directory creation is working perfectly, but when it comes to adding the following code to upload an index.php file into the 'new' directory, nothing is happening:

    $my_file = 'index.php';
    $handle = fopen($my_file, 'w') or die('Cannot open file: '.$my_file);
    The index.php file is basically a templated layout that will read the directory name, in addition to some random array stuff to generate a bunch of text while also pulling a list of data from my database to display on the index page of the new directory.

    Could someone with a little more knowledge take a moment to point me in the right direction on how I get the new page creation to work please?

    Im not getting any error logs when the button on the submit form is clicked
    Extreme Link List - v1.0
  • ZTT
    Confirmed User
    • Apr 2019
    • 659

    #2
    You're not writing anything so obviously nothing will be written.

    If all you're doing is copying an existing template to a new directory then:

    <?php

    $mytemplate="mytemplate.txt";

    $newfolder="new";

    mkdir($newfolder);

    copy($mytemplate,$newfolder."/".$mytemplate);

    ?>
    __________________

    Comment

    • Publisher Bucks
      Confirmed User
      • Oct 2018
      • 1330

      #3
      Originally posted by ZTT
      You're not writing anything so obviously nothing will be written.

      If all you're doing is copying an existing template to a new directory then:

      <?php

      $mytemplate="mytemplate.txt";

      $newfolder="new";

      mkdir($newfolder);

      copy($mytemplate,$newfolder."/".$mytemplate);

      ?>
      Yes, but I can't use that as part of an admin backend without editing it every single time.

      I need a html form to be able to name the new directory which also needs to upload that file based on an existing template, Im not having 8 or so people who use this system be able to log into the server to do that manually each time, it defeats the purpose of having a backend system to do it

      It also means I need to make sure the people using the php you suggested, are competant when it comes to logging onto the server and arent going to fuck anything thats already in place, up.
      Extreme Link List - v1.0

      Comment

      • ZTT
        Confirmed User
        • Apr 2019
        • 659

        #4
        Originally posted by Publisher Bucks
        Yes, but I can't use that as part of an admin backend without editing it every single time.
        Editing what? The subject says you want to create a folder and put a template into the new folder. Do you even know what a template is?

        Im not having 8 or so people who use this system be able to log into the server to do that manually each time, it defeats the purpose of having a backend system to do it
        How am I supposed to know what you are doing or what you will or will not allow other people to do? In your post you said:

        I'm currently trying to get a part of an admin system setup whereby I can create a new sub directory on a domain, I have that part working however, I'm having issues putting a .php template into the directory once it has been created.

        Here is the code I'm using to create the directory itself on the server:
        Nowhere does it say Fiverr monkeys are uploading files that "change every time". In fact it pretty much says the opposite of that.

        I need a html form to be able to name the new directory which also needs to upload that file based on an existing template,
        A file based on a template is not a template, and if all you want to do is upload a file that's already generated, based on whatever, then use a upload script.

        1. mkdir "dir"

        2. Upload to "dir"

        It also means I need to make sure the people using the php you suggested, are competant when it comes to logging onto the server and arent going to fuck anything thats already in place, up.
        If you were competent enough to explain what you want, you might get the answers you want.
        __________________

        Comment

        Working...