FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Failed to write to a text file (text file is RW)
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Failed to write to a text file (text file is RW) [message #171421 is a reply to message #171418] Sun, 02 January 2011 23:26 Go to previous messageGo to previous message
justaguy is currently offline  justaguy
Messages: 16
Registered: December 2010
Karma:
Junior Member
On Jan 2, 5:00 pm, Denis McMahon <denis.m.f.mcma...@googlemail.com>
wrote:
> On 02/01/11 20:19, justaguy wrote:
>
>> I dig up the following script.  Added a simple HTML file with a form
>> field named "vote" and have it send to the following php script.
>> However, it failed to write to the poll_result.txt file.  Why?
>
> The following seems to work for me.
>
> <?php
> $filename = "poll_result.txt";
> if (isset($_POST['vote'])) {
>   $vote = intval($_POST['vote']); // get this vote
>   $content = file($filename); // read result file
>   $array = explode("||", $content[0]);
>   $yes = intval($array[0]); // get stored results
>   $no = intval($array[1]);
>   if ($vote == 1) $yes++; // increment one
>   if ($vote == 0) $no++;
>   $insertvote = $yes."||".$no; // new result string
>   }
> else {
>   $insertvote = "0||0\n"; // reset result string
>   $yes = 0;
>   $no = 0;
>   }
> $fp = fopen($filename,"w"); // store results
> fputs($fp,$insertvote);
> fclose($fp);
> echo <<<EOT
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
> "http://www.w3.org/TR/html4/strict.dtd">
> <html>
> <head>
> <title>Yes-No Poll</title>
> </head>
> <body style="padding:1em 3em">
> <form method="post" action="quickpoll.php" name="f1" id="f1">
> <p>Yes: <input type="radio" name="vote" id="v1_1" value="1"><br>
> No: <input type="radio" name="vote" id="v1_0" value="0"><br>
> <input type="submit" value="Vote Now" name="s1" id="s1"></p>
> </form>
> <p>The results so far:<br>
> Yes: $yes votes<br>
> No: $no votes</p>
> </body>
> </html>
> EOT;
> ?>
>
> Rgds
>
> Denis McMahon

Denis,

I still failed to write to the poll_result.txt file and I noticed
there's a slight difference between this file's access attributes
compared to a similar target text file with a similar script and
process. The other target text file has rwxrwxrwx attributes while
this one has rwrwrw attributes. I thought the global writable would
suffice but it seems I was incorrect. My ftp client failed to do
chmod 755 to the global x (execute) attribute to the file.

Thanks though.

Don
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Print PHP Manual
Next Topic: Fetching an external web page
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sat Nov 23 07:39:39 GMT 2024

Total time taken to generate the page: 0.04829 seconds