Create folder help

Discussion in 'PHP' started by badmasketa, Jun 9, 2008.

  1. #1
    how to create folder name from user inputs with the folder permissions?

    if users input the folder name from the form below, i wanna now create the folder from that folder name (if users enters space between the folder name then i want "_" to be included in between the names; like Folder_name)

    <form id="form1" name="form1" method="post" action="create.php">
      <table width="29%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td>Name :</td>
          <td><label>
            <input type="text" name="name" id="name" />
          </label></td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td><label>
            <input type="submit" name="button" id="button" value="Submit" />
          </label></td>
        </tr>
      </table>
    </form>
    Code (markup):
    could you please help me out??
     
    badmasketa, Jun 9, 2008 IP
  2. Lucas3677

    Lucas3677 Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    http://ca.php.net/manual/en/function.mkdir.php

    <?php
    
    mkdir('/path/to/dir/' . str_replace(' ', '_', $_POST['name']), 0777);
    
    ?>
    PHP:
    Of course you should do more validation that that (in case the user enters a / or other illegal character).
     
    Lucas3677, Jun 9, 2008 IP
  3. badmasketa

    badmasketa Well-Known Member

    Messages:
    351
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    103
    #3
    OK thanks for the code, and how would i remove off the unnecessary characters if users input that, and also, how to check if there's already the folder with same name, and show error message...
     
    badmasketa, Jun 9, 2008 IP
  4. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #4
    Danltn, Jun 9, 2008 IP