Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New to the CF scene
    Join Date
    Apr 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Data from form into variable textfile

    I try to put data from a form in a txt file, the txt file is named after one of the fields.

    The code below is what i got, but its not generating a <name>.txt file

    it also dont generate an error, can someone tell me whats wrong with it?
    :confused:

    PHP Code:

    <? 
    error_reporting
    (E_ALL); 
    ?>
    <?php
    if ($_SERVER'REQUEST_METHOD'] == 'POST')
    {
    $filename = ($_POST['achternaam''.txt''w');
    $f0;   
    $voorn$_POST['voornaam'];   
    $achtern$_POST['achternaam'];   
    $adres $_POST['straat'][$f]['nummer'];   
    $input $voorn."|".$achtern."|".$adres."\n"


    if (
    is_writable($filename)) {

       
       if (!
    $handle fopen($filename)) {
             echo 
    "Cannot open file ($filename)";
             exit;
       }

       if (
    fwrite($handle$input) === FALSE) {
           echo 
    "Cannot write to file ($filename)";
           exit;
       }
       
       echo 
    "Success, wrote ($input) to file ($filename)";
       
       
    fclose($handle);
                       
    } else {
       echo 
    "The file $filename is not writable";
    }
    ?>
    Last edited by Spookster; 04-20-2004 at 11:35 PM.

  • #2
    Regular Coder
    Join Date
    Mar 2004
    Posts
    115
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
     <?php
    error_reporting
    (E_ALL);
    //if ($_SERVER['REQUEST_METHOD'] == 'POST')
    //{
    $filename $_POST['achternaam']."txt"//fixed here
    $f0
    $voorn$_POST['voornaam']; 
    $achtern$_POST['achternaam']; 
    $adres $_POST['straat'][$f]['nummer']; 
    $input $voorn."|".$achtern."|".$adres."\n"


    if (
    is_writable($filename)) {


    if (!
    $handle fopen($filename,w)) { //fixed here
    echo "Cannot open file ($filename)";
    exit;
    }

    if (
    fwrite($handle$input) === FALSE) {
    echo 
    "Cannot write to file ($filename)";
    exit;
    }

    echo 
    "Success, wrote ($input) to file ($filename)";

    fclose($handle);

    } else {
    echo 
    "The file $filename is not writable";
    }

  • #3
    New to the CF scene
    Join Date
    Apr 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks, i make progres i get a response now:

    The file name.txt is not writable

    so in theorie its working, but i cant put the data in because its not chmod
    i guess, so how can i chmod a file that is generated ?

    chmod($filename, 0666) didnt do the trick

  • #4
    Regular Coder
    Join Date
    Mar 2004
    Posts
    115
    Thanks
    0
    Thanked 0 Times in 0 Posts
    the file dosent exsist so it wont ever be writable

    open file dont do is writable and chmod the directory that the file is

    being created in

  • #5
    New to the CF scene
    Join Date
    Apr 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question

    bet you can tell im new to this..

    I changed it to this:

    PHP Code:

    <?php 
    error_reporting
    (E_ALL); 
    ?> 
    <?php
    $filename 
    $_POST['achternaam'].".txt"
    $f0;  
    $voorn$_POST['voornaam'];  
    $achtern$_POST['achternaam'];  
    $adres $_POST['straat'][$f]['nummer'];  
    $input $voorn."|".$achtern."|".$adres."\n";  
    chmod("D:/web/rob"0777); //fixed here 


    $handle fopen($filename,'w'))  //fixed here 

    if (fwrite($handle$input) === FALSE) { 
    echo 
    "Cannot write to file ($filename)"
    exit; 


    echo 
    "Success, wrote ($input) to file ($filename)"

    fclose($handle); 


    ?>
    So i open the file direct en i chmod the directory, but its all white again, and no file made
    Last edited by Spookster; 04-20-2004 at 11:35 PM.

  • #6
    Regular Coder
    Join Date
    Mar 2004
    Posts
    115
    Thanks
    0
    Thanked 0 Times in 0 Posts
    are you test on a linux or widows server

  • #7
    New to the CF scene
    Join Date
    Apr 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm using apache server on windows XP with php4

  • #8
    Regular Coder
    Join Date
    Mar 2004
    Posts
    115
    Thanks
    0
    Thanked 0 Times in 0 Posts
    chmod is for linux/unix permission

    you will need to give the directory permission through internet servises

  • #9
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Bigbird,

    When posting your code in our forums please use the special php tags so that your code will be formatted in a way that is much more readable. You can read about how to use those tags in the FAQ:

    http://www.codingforums.com/misc.php?do=bbcode#php

    I've updated your two previous posts using the php tag so you can see how much more readable it becomes.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •