SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Creating Files

Hybrid View

  1. #1
    Non-Member MrLister's Avatar
    Join Date
    Feb 2001
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Creating Files

    Is there a way to create files such as config.ini thoruhg a form. so they put in all the stuff they want and press submit and then the file is created with their settings in it.

  2. #2
    SitePoint Evangelist ucahg's Avatar
    Join Date
    Apr 2001
    Location
    Sarnia, Ontario, Canada
    Posts
    434
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Run a search on php.net for file handling commands.
    Love it? Hate it? Helpful? Useless?
    Use the rate button to let me know what you think of my post!

  3. #3
    SitePoint Addict zoordaan's Avatar
    Join Date
    Feb 2001
    Location
    NYC/Texas
    Posts
    348
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The file server.conf or what ever it's caled, should be mode 777

    Code:
    <form name="" method="post" action="<?=$PHP_SELF?>">
    Server: <input type="text" name="server" value="<? echo $server; ?>"><p>
    Port: <input type="text" name="port" value="<? echo $port; ?>"><p>
    Type of Database: <input type="text" name="type_of_db" value="<? echo $type_of_db; ?>"><p>
    Name of Database: <input type="text" name="name_of_db" value="<? echo $name_of_db; ?>"><p>
    <input type="submit" name="submit" value="modify/submit">
    </form>
    
    <?php
    if($submit){
    if (isset($server) && isset($port) && isset($type_of_db) && isset($name_of_db)){
    
    $fp= fopen("server.conf", "w+");
    
    fwrite($fp,$server."|"); 
    fwrite($fp,$port."|"); 
    fwrite($fp,$type_of_db."|"); 
    fwrite($fp,$name_of_db."\n"); 
    fclose($fp);
    /*
    You will have a file like this one: 
    server|port|type of db|name of db
    www.server.com|80|mysql|test
    */
    }
    
    }
    
    ?>
    
    <?
    //to read the file use: 
    $fp2= fopen("server.conf", "r");
    $servinfo=fgetcsv($fp2,4096,"|"); 
    
    list($server,$port,$type_of_db,$name_of_db)= $servinfo; 
    
    fclose($fp2);
    ?>


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
  •