PDA

View Full Version : Data from form into variable textfile



bigbird
04-20-2004, 09:46 PM
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:




<?
error_reporting(E_ALL);
?>
<?php
if ($_SERVER[ 'REQUEST_METHOD'] == 'POST')
{
$filename = ($_POST['achternaam'] '.txt', 'w');
$f= 0;
$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";
}
?>

sidney
04-20-2004, 11:08 PM
<?php
error_reporting(E_ALL);
//if ($_SERVER['REQUEST_METHOD'] == 'POST')
//{
$filename = $_POST['achternaam']."txt"; //fixed here
$f= 0;
$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";
}

bigbird
04-20-2004, 11:25 PM
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

sidney
04-20-2004, 11:31 PM
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

bigbird
04-20-2004, 11:39 PM
bet you can tell im new to this..

I changed it to this:




<?php
error_reporting(E_ALL);
?>
<?php
$filename = $_POST['achternaam'].".txt";
$f= 0;
$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

sidney
04-20-2004, 11:57 PM
are you test on a linux or widows server

bigbird
04-21-2004, 12:00 AM
I'm using apache server on windows XP with php4

sidney
04-21-2004, 12:08 AM
chmod is for linux/unix permission

you will need to give the directory permission through internet servises

Spookster
04-21-2004, 12:34 AM
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.