auto create page

Discussion in 'PHP' started by chaty1, Jan 31, 2010.

  1. #1
    Hi i need a program that will copy,create a page when the user pushes submit button. It most be able to check directory to see if page exist.
     
    chaty1, Jan 31, 2010 IP
  2. OwenMelbz

    OwenMelbz Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    not really enough information there really..

    like what must it do if the page exists, how does the person pick which page to copy, or how do they decide if they want to make a new one or copy one?

    bit vague, explain it more
     
    OwenMelbz, Jan 31, 2010 IP
  3. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #3
    Your description is very vague, but try this (off the top of my head).

    <?php
    
    if(isset($_POST['submit']) && !empty($_POST['page'])){
    
    //basic security
    if(ctype_alnum($_POST['page']) == true){
    
    //this is the type of file you want to be created.
    $ext = ".txt";
    
    $FileName = $_POST['page'].$ext;
    
    //check it doesn't exist already
    if(!file_exists($FileName)){
    $FileHandle = fopen($FileName, 'w') or die("can't open file");
    fclose($FileHandle);
    
    echo "<a href=\"".$FileName."\">".$_POST['page']."</a> has been created sucessfully!";
    } else {
    
    echo "Page already exists";
    
    }
    } else {
    
    echo "Invalid page name, must be numbers and letters only!";
    }
    
    }
    
    ?>
    
    <form action="#" method="post">
    
    Page Name: <input type="text" name="page"><br />
    
    <input type="submit" name="submit" value="Submit">
    
    </form>
    PHP:
     
    danx10, Jan 31, 2010 IP
  4. OwenMelbz

    OwenMelbz Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    does that copy any files tho?
     
    OwenMelbz, Jan 31, 2010 IP
  5. aljosabre

    aljosabre Peon

    Messages:
    45
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0