f



Failed to write to a text file (text file is RW)

Hi,

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?

Thanks as usual.

<?php
$vote = $_REQUEST['vote'];

//get content of textfile
$filename = "poll_result.txt";
$content = file($filename);

//put content in array
$array = explode("||", $content[0]);
$yes = $array[0];
$no = $array[1];

if ($vote == 1)
  {
  $yes = $yes + 1;
  }
if ($vote == 0)
  {
  $no = $no + 1;
  }


// debug
echo $yes;
echo $no;

// output and comments
/*
Seed poll_result.txt to read  0||0

It's always 10 even though I checked the YES option several times
obviously it failed to write to the poll_result.txt file.

Checked the poll_result.txt, it's 0||0

*/


//insert votes to txt file
$insertvote = $yes."||".$no;
$fp = fopen($filename,"w");
fputs($fp,$insertvote);
fclose($fp);
?>
0
donli (155)
1/2/2011 8:19:06 PM
comp.lang.php 32646 articles. 0 followers. Post Follow

29 Replies
1211 Views

Similar Articles

[PageSpeed] 8

On 1/2/2011 3:19 PM, justaguy wrote:
> Hi,
>
> 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?
>
> Thanks as usual.
>
> <?php
> $vote = $_REQUEST['vote'];
>
> //get content of textfile
> $filename = "poll_result.txt";
> $content = file($filename);
>
> //put content in array
> $array = explode("||", $content[0]);
> $yes = $array[0];
> $no = $array[1];
>
> if ($vote == 1)
>    {
>    $yes = $yes + 1;
>    }
> if ($vote == 0)
>    {
>    $no = $no + 1;
>    }
>
>
> // debug
> echo $yes;
> echo $no;
>
> // output and comments
> /*
> Seed poll_result.txt to read  0||0
>
> It's always 10 even though I checked the YES option several times
> obviously it failed to write to the poll_result.txt file.
>
> Checked the poll_result.txt, it's 0||0
>
> */
>
>
> //insert votes to txt file
> $insertvote = $yes."||".$no;
> $fp = fopen($filename,"w");
> fputs($fp,$insertvote);
> fclose($fp);
> ?>

Are you sure you're looking at the same file you're writing to?  You're 
using a relative path, after all (which would place the data file in 
your web path, where it could be downloaded by anyone - not a good idea).

Does the user (if this is running under the web server, the web server 
user) have permission to write to the file?

And finally, this is totally unsafe.  There is nothing stopping two 
different people from opening the file at the same time, potentially 
corrupting your date.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
0
jstucklex (14659)
1/2/2011 8:35:14 PM
On Jan 2, 3:35=A0pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> On 1/2/2011 3:19 PM, justaguy wrote:
>
>
>
> > Hi,
>
> > I dig up the following script. =A0Added 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. =A0Why?
>
> > Thanks as usual.
>
> > <?php
> > $vote =3D $_REQUEST['vote'];
>
> > //get content of textfile
> > $filename =3D "poll_result.txt";
> > $content =3D file($filename);
>
> > //put content in array
> > $array =3D explode("||", $content[0]);
> > $yes =3D $array[0];
> > $no =3D $array[1];
>
> > if ($vote =3D=3D 1)
> > =A0 =A0{
> > =A0 =A0$yes =3D $yes + 1;
> > =A0 =A0}
> > if ($vote =3D=3D 0)
> > =A0 =A0{
> > =A0 =A0$no =3D $no + 1;
> > =A0 =A0}
>
> > // debug
> > echo $yes;
> > echo $no;
>
> > // output and comments
> > /*
> > Seed poll_result.txt to read =A00||0
>
> > It's always 10 even though I checked the YES option several times
> > obviously it failed to write to the poll_result.txt file.
>
> > Checked the poll_result.txt, it's 0||0
>
> > */
>
> > //insert votes to txt file
> > $insertvote =3D $yes."||".$no;
> > $fp =3D fopen($filename,"w");
> > fputs($fp,$insertvote);
> > fclose($fp);
> > ?>
>
> Are you sure you're looking at the same file you're writing to? =A0You're
> using a relative path, after all (which would place the data file in
> your web path, where it could be downloaded by anyone - not a good idea).
>
> Does the user (if this is running under the web server, the web server
> user) have permission to write to the file?
>
> And finally, this is totally unsafe. =A0There is nothing stopping two
> different people from opening the file at the same time, potentially
> corrupting your date.
>
> --
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck...@attglobal.net
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D

Well, on "where it could be downloaded by anyone", how come?  The
processPoll.php file or a similar process php script is a server
script,
average user can't mess up with it.

On file permission, sorry, I forgot to mention, it's Read and Write.
A similar php script executes fine.

On your last point of " this is totally unsafe.  There is nothing
stopping two
> different people from opening the file at the same time, potentially
> corrupting your date."
Once we fix the above two problems what could we do about it?  I'm
totally new to php btw.

Many thanks.


0
donli (155)
1/2/2011 9:07:50 PM
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
0
1/2/2011 10:00:08 PM
On 1/2/2011 4:07 PM, justaguy wrote:
> On Jan 2, 3:35 pm, Jerry Stuckle<jstuck...@attglobal.net>  wrote:
>> On 1/2/2011 3:19 PM, justaguy wrote:
>>
>>
>>
>>> Hi,
>>
>>> 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?
>>
>>> Thanks as usual.
>>
>>> <?php
>>> $vote = $_REQUEST['vote'];
>>
>>> //get content of textfile
>>> $filename = "poll_result.txt";
>>> $content = file($filename);
>>
>>> //put content in array
>>> $array = explode("||", $content[0]);
>>> $yes = $array[0];
>>> $no = $array[1];
>>
>>> if ($vote == 1)
>>>     {
>>>     $yes = $yes + 1;
>>>     }
>>> if ($vote == 0)
>>>     {
>>>     $no = $no + 1;
>>>     }
>>
>>> // debug
>>> echo $yes;
>>> echo $no;
>>
>>> // output and comments
>>> /*
>>> Seed poll_result.txt to read  0||0
>>
>>> It's always 10 even though I checked the YES option several times
>>> obviously it failed to write to the poll_result.txt file.
>>
>>> Checked the poll_result.txt, it's 0||0
>>
>>> */
>>
>>> //insert votes to txt file
>>> $insertvote = $yes."||".$no;
>>> $fp = fopen($filename,"w");
>>> fputs($fp,$insertvote);
>>> fclose($fp);
>>> ?>
>>
>> Are you sure you're looking at the same file you're writing to?  You're
>> using a relative path, after all (which would place the data file in
>> your web path, where it could be downloaded by anyone - not a good idea).
>>
>> Does the user (if this is running under the web server, the web server
>> user) have permission to write to the file?
>>
>> And finally, this is totally unsafe.  There is nothing stopping two
>> different people from opening the file at the same time, potentially
>> corrupting your date.
>>
>> --
>> ==================
>> Remove the "x" from my email address
>> Jerry Stuckle
>> JDS Computer Training Corp.
>> jstuck...@attglobal.net
>> ==================
>
> Well, on "where it could be downloaded by anyone", how come?  The
> processPoll.php file or a similar process php script is a server
> script,
> average user can't mess up with it.
>

That's fine - but the data file itself is in the same directory - where 
a knowledgeable user has direct access to it.

> On file permission, sorry, I forgot to mention, it's Read and Write.
> A similar php script executes fine.
>

read/write for whom?

> On your last point of " this is totally unsafe.  There is nothing
> stopping two
>> different people from opening the file at the same time, potentially
>> corrupting your date."
> Once we fix the above two problems what could we do about it?  I'm
> totally new to php btw.
>
> Many thanks.
>
>

Has nothing to do with PHP - this can occur in ANY language.  You need 
to learn all about how to work in a multitasking environment. Basically, 
you have to limit access to the file so that only one script can access 
it at a time.  How you do it is dependent on the OS.

Or you can use a database which is built for multitasking (most are).

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
0
jstucklex (14659)
1/2/2011 10:13:31 PM
On Jan 2, 5:00=A0pm, Denis McMahon <denis.m.f.mcma...@googlemail.com>
wrote:
> On 02/01/11 20:19, justaguy wrote:
>
> > I dig up the following script. =A0Added 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. =A0Why?
>
> The following seems to work for me.
>
> <?php
> $filename =3D "poll_result.txt";
> if (isset($_POST['vote'])) {
> =A0 $vote =3D intval($_POST['vote']); // get this vote
> =A0 $content =3D file($filename); // read result file
> =A0 $array =3D explode("||", $content[0]);
> =A0 $yes =3D intval($array[0]); // get stored results
> =A0 $no =3D intval($array[1]);
> =A0 if ($vote =3D=3D 1) $yes++; // increment one
> =A0 if ($vote =3D=3D 0) $no++;
> =A0 $insertvote =3D $yes."||".$no; // new result string
> =A0 }
> else {
> =A0 $insertvote =3D "0||0\n"; // reset result string
> =A0 $yes =3D 0;
> =A0 $no =3D 0;
> =A0 }
> $fp =3D 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=3D"padding:1em 3em">
> <form method=3D"post" action=3D"quickpoll.php" name=3D"f1" id=3D"f1">
> <p>Yes: <input type=3D"radio" name=3D"vote" id=3D"v1_1" value=3D"1"><br>
> No: <input type=3D"radio" name=3D"vote" id=3D"v1_0" value=3D"0"><br>
> <input type=3D"submit" value=3D"Vote Now" name=3D"s1" id=3D"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
0
donli (155)
1/2/2011 11:26:10 PM
On 02/01/11 23:26, justaguy wrote:

> 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.

Shouldn't need execute access to write, can you check the logs and see
if there's a php error being recorded when you try and write the file?

Rgds

Denis McMahon
0
1/2/2011 11:51:18 PM
justaguy wrote:

> Denis McMahon 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
>> […]
>> EOT;
>> ?>
> 
> 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. 

This is commonly written `rw-rw-rw-' or `chmod 666' instead.  Rule of thumb: 
r = 4, w = 2, x = 1; addition provides the number.

> 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.

You would be well-advised to get the basics right first.

  1. If you had previously `rw-rw-rw-' or `chmod 666', you would need
     to do `chmod o+x' or `chmod 777' to get `rwxrwxrwx'.

  2. In which mode you can open a file has not so much to do with that
     file's permissions.  More important are the ownership of the file,
     the permissions of the directory the file is located in, and who/
     what else has that file already open.

  3. A text file's *executable* bit of course has nothing to do with
     whether or not you can read from or write to this file (regarding
     PHP, it is relevant for CGI scripts only).  However, the read and
     executable permission bits of its directory are relevant for reading,
     and the directorie's write permission bit is relevant for creating
     a new file.

  4. There is no "global writable" or "global x (execute) attribute".
     The first _permissions_ triple applies only to the owner of the file,
     the second to all users of the group which owns the file, and the
     the third one to all *other* users.

     Usually PHP is not run by the owner or the group of the file, but
     by the Web server; this is either run by root or by a special system
     user (e.g. www-data), which usually is not the owner nor is its group
     the owning group.

     So the *third* permissions triple is relevant, not the first.

And please trim your quotes to the parts you are referring to.


PointedEars
-- 
Danny Goodman's books are out of date and teach practices that are
positively harmful for cross-browser scripting.
 -- Richard Cornford, cljs, <cife6q$253$1$8300dec7@news.demon.co.uk> (2004)
0
PointedEars (2489)
1/2/2011 11:54:35 PM
On 1/2/2011 6:26 PM, justaguy wrote:
> 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

You do not need execute privileges to write the file - in fact, you 
should NOT have it - the file is not an executable.  You also definitely 
should NOT have global write (or read) privileges.

Did you check the return value from fopen()?  ALWAYS check it to ensure 
that the file opened correctly.  Also, do you know if the fread() and/or 
fwrite() worked correctly?  You never check to see.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
0
jstucklex (14659)
1/2/2011 11:55:59 PM
On 1/2/2011 5:00 PM, Denis McMahon 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

Like the original op's, your code is totally unsafe in a multitasking 
environment.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
0
jstucklex (14659)
1/2/2011 11:56:41 PM
On Jan 2, 6:55=A0pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> On 1/2/2011 6:26 PM, justaguy wrote:
>
>
>
> > 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. =A0Added a simple HTML file with a for=
m
> >>> field named "vote" and have it send to the following php script.
> >>> However, it failed to write to the poll_result.txt file. =A0Why?
>
> >> The following seems to work for me.
>
> >> <?php
> >> $filename =3D "poll_result.txt";
> >> if (isset($_POST['vote'])) {
> >> =A0 =A0$vote =3D intval($_POST['vote']); // get this vote
> >> =A0 =A0$content =3D file($filename); // read result file
> >> =A0 =A0$array =3D explode("||", $content[0]);
> >> =A0 =A0$yes =3D intval($array[0]); // get stored results
> >> =A0 =A0$no =3D intval($array[1]);
> >> =A0 =A0if ($vote =3D=3D 1) $yes++; // increment one
> >> =A0 =A0if ($vote =3D=3D 0) $no++;
> >> =A0 =A0$insertvote =3D $yes."||".$no; // new result string
> >> =A0 =A0}
> >> else {
> >> =A0 =A0$insertvote =3D "0||0\n"; // reset result string
> >> =A0 =A0$yes =3D 0;
> >> =A0 =A0$no =3D 0;
> >> =A0 =A0}
> >> $fp =3D 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=3D"padding:1em 3em">
> >> <form method=3D"post" action=3D"quickpoll.php" name=3D"f1" id=3D"f1">
> >> <p>Yes:<input type=3D"radio" name=3D"vote" id=3D"v1_1" value=3D"1"><br=
>
> >> No:<input type=3D"radio" name=3D"vote" id=3D"v1_0" value=3D"0"><br>
> >> <input type=3D"submit" value=3D"Vote Now" name=3D"s1" id=3D"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. =A0The other target text file has rwxrwxrwx attributes while
> > this one has rwrwrw attributes. =A0I thought the global writable would
> > suffice but it seems I was incorrect. =A0My ftp client failed to do
> > chmod 755 to the global x (execute) attribute to the file.
>
> > Thanks though.
>
> > Don
>
> You do not need execute privileges to write the file - in fact, you
> should NOT have it - the file is not an executable. =A0You also definitel=
y
> should NOT have global write (or read) privileges.
>
> Did you check the return value from fopen()? =A0ALWAYS check it to ensure
> that the file opened correctly. =A0Also, do you know if the fread() and/o=
r
> fwrite() worked correctly? =A0You never check to see.
>
> --
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck...@attglobal.net
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D

Jerry,

Here's the block of code with debugging info and it still has a
problem:
//insert votes to txt file
$insertvote =3D $yes."||".$no;
$fp =3D fopen($filename,"w");
echo "fp;";
echo $fp;

fputs($fp,$insertvote);
echo "insert; ";
echo $insertvote;
fclose($fp);

And here's its output:
10 fp;insert; 1||0

Which seems to suggest the operation of $fp =3D fopen($filename,"w")
failed.

// the poll_result.txt file is in the same directory
$filename =3D "poll_result.txt";

/* why ok with another php script?
Why a similar statement for file read in another script is ok.
$myFile =3D "someLog.txt";
*/

And yes, I know the 'x' bit isn't necessary.  Odd.   Thanks.
0
donli (155)
1/3/2011 1:04:04 AM
On 1/2/2011 8:04 PM, justaguy wrote:
> On Jan 2, 6:55 pm, Jerry Stuckle<jstuck...@attglobal.net>  wrote:
>> On 1/2/2011 6:26 PM, justaguy wrote:
>>
>>
>>
>>> 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
>>
>> You do not need execute privileges to write the file - in fact, you
>> should NOT have it - the file is not an executable.  You also definitely
>> should NOT have global write (or read) privileges.
>>
>> Did you check the return value from fopen()?  ALWAYS check it to ensure
>> that the file opened correctly.  Also, do you know if the fread() and/or
>> fwrite() worked correctly?  You never check to see.
>>
>> --
>> ==================
>> Remove the "x" from my email address
>> Jerry Stuckle
>> JDS Computer Training Corp.
>> jstuck...@attglobal.net
>> ==================
>
> Jerry,
>
> Here's the block of code with debugging info and it still has a
> problem:
> //insert votes to txt file
> $insertvote = $yes."||".$no;
> $fp = fopen($filename,"w");
> echo "fp;";
> echo $fp;
>
> fputs($fp,$insertvote);
> echo "insert; ";
> echo $insertvote;
> fclose($fp);
>
> And here's its output:
> 10 fp;insert; 1||0
>
> Which seems to suggest the operation of $fp = fopen($filename,"w")
> failed.
>
> // the poll_result.txt file is in the same directory
> $filename = "poll_result.txt";
>
> /* why ok with another php script?
> Why a similar statement for file read in another script is ok.
> $myFile = "someLog.txt";
> */
>
> And yes, I know the 'x' bit isn't necessary.  Odd.   Thanks.

I'm not talking about 'debug code' - I'm talking about actual code you 
should have in every script - error checking.

NEVER assume an external operation works. You should ALWAYS check the 
return code, especially where external operations are concerned, and if 
you get a bad one, you should take correct action.

fopen() returns false if the file was not opened.  So your current 
example should have checked for a failure in fopen and taken the 
appropriate action.  For testing purposes, displaying a message would be 
sufficient.  You would not want to do that on a production server, of 
course, but you should at least log the error.

Had you had such code in place, you would have known that the fopen() 
failed and could have followed down why.  And if this is your 
development server, you should have in your php.ini:

display_errors=on
error_reporting=E_ALL  (or E_ALL | E_STRICT)

These would have given you additional messages. But you don't want these 
on a production server; instead you should log your PHP errors to a file 
and look at that file when you have problems.



-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
0
jstucklex (14659)
1/3/2011 1:34:42 AM
On Jan 2, 8:34=A0pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> On 1/2/2011 8:04 PM, justaguy wrote:
>
>
>
> > On Jan 2, 6:55 pm, Jerry Stuckle<jstuck...@attglobal.net> =A0wrote:
> >> On 1/2/2011 6:26 PM, justaguy wrote:
>
> >>> 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. =A0Added a simple HTML file with a f=
orm
> >>>>> field named "vote" and have it send to the following php script.
> >>>>> However, it failed to write to the poll_result.txt file. =A0Why?
>
> >>>> The following seems to work for me.
>
> >>>> <?php
> >>>> $filename =3D "poll_result.txt";
> >>>> if (isset($_POST['vote'])) {
> >>>> =A0 =A0 $vote =3D intval($_POST['vote']); // get this vote
> >>>> =A0 =A0 $content =3D file($filename); // read result file
> >>>> =A0 =A0 $array =3D explode("||", $content[0]);
> >>>> =A0 =A0 $yes =3D intval($array[0]); // get stored results
> >>>> =A0 =A0 $no =3D intval($array[1]);
> >>>> =A0 =A0 if ($vote =3D=3D 1) $yes++; // increment one
> >>>> =A0 =A0 if ($vote =3D=3D 0) $no++;
> >>>> =A0 =A0 $insertvote =3D $yes."||".$no; // new result string
> >>>> =A0 =A0 }
> >>>> else {
> >>>> =A0 =A0 $insertvote =3D "0||0\n"; // reset result string
> >>>> =A0 =A0 $yes =3D 0;
> >>>> =A0 =A0 $no =3D 0;
> >>>> =A0 =A0 }
> >>>> $fp =3D 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=3D"padding:1em 3em">
> >>>> <form method=3D"post" action=3D"quickpoll.php" name=3D"f1" id=3D"f1"=
>
> >>>> <p>Yes:<input type=3D"radio" name=3D"vote" id=3D"v1_1" value=3D"1"><=
br>
> >>>> No:<input type=3D"radio" name=3D"vote" id=3D"v1_0" value=3D"0"><br>
> >>>> <input type=3D"submit" value=3D"Vote Now" name=3D"s1" id=3D"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. =A0The other target text file has rwxrwxrwx attributes while
> >>> this one has rwrwrw attributes. =A0I thought the global writable woul=
d
> >>> suffice but it seems I was incorrect. =A0My ftp client failed to do
> >>> chmod 755 to the global x (execute) attribute to the file.
>
> >>> Thanks though.
>
> >>> Don
>
> >> You do not need execute privileges to write the file - in fact, you
> >> should NOT have it - the file is not an executable. =A0You also defini=
tely
> >> should NOT have global write (or read) privileges.
>
> >> Did you check the return value from fopen()? =A0ALWAYS check it to ens=
ure
> >> that the file opened correctly. =A0Also, do you know if the fread() an=
d/or
> >> fwrite() worked correctly? =A0You never check to see.
>
> >> --
> >> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> >> Remove the "x" from my email address
> >> Jerry Stuckle
> >> JDS Computer Training Corp.
> >> jstuck...@attglobal.net
> >> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
>
> > Jerry,
>
> > Here's the block of code with debugging info and it still has a
> > problem:
> > //insert votes to txt file
> > $insertvote =3D $yes."||".$no;
> > $fp =3D fopen($filename,"w");
> > echo "fp;";
> > echo $fp;
>
> > fputs($fp,$insertvote);
> > echo "insert; ";
> > echo $insertvote;
> > fclose($fp);
>
> > And here's its output:
> > 10 fp;insert; 1||0
>
> > Which seems to suggest the operation of $fp =3D fopen($filename,"w")
> > failed.
>
> > // the poll_result.txt file is in the same directory
> > $filename =3D "poll_result.txt";
>
> > /* why ok with another php script?
> > Why a similar statement for file read in another script is ok.
> > $myFile =3D "someLog.txt";
> > */
>
> > And yes, I know the 'x' bit isn't necessary. =A0Odd. =A0 Thanks.
>
> I'm not talking about 'debug code' - I'm talking about actual code you
> should have in every script - error checking.
>
> NEVER assume an external operation works. You should ALWAYS check the
> return code, especially where external operations are concerned, and if
> you get a bad one, you should take correct action.
>
> fopen() returns false if the file was not opened. =A0So your current
> example should have checked for a failure in fopen and taken the
> appropriate action. =A0For testing purposes, displaying a message would b=
e
> sufficient. =A0You would not want to do that on a production server, of
> course, but you should at least log the error.
>
> Had you had such code in place, you would have known that the fopen()
> failed and could have followed down why. =A0And if this is your
> development server, you should have in your php.ini:
>
> display_errors=3Don
> error_reporting=3DE_ALL =A0(or E_ALL | E_STRICT)
>
> These would have given you additional messages. But you don't want these
> on a production server; instead you should log your PHP errors to a file
> and look at that file when you have problems.
>
> --
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck...@attglobal.net
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D

Jerry,

The code isn't working, so, of course it's not in production.  I'm
using an ISP's server, don't have a lot of control...
yes, you're right, I was lazy in error detection/tracking for this
piece of code, thought it should be fairly straight-forward.

Thanks.

Don
0
donli (155)
1/3/2011 2:13:34 AM
On 1/2/2011 9:13 PM, justaguy wrote:
> On Jan 2, 8:34 pm, Jerry Stuckle<jstuck...@attglobal.net>  wrote:
>> On 1/2/2011 8:04 PM, justaguy wrote:
>>
>>
>>
>>> On Jan 2, 6:55 pm, Jerry Stuckle<jstuck...@attglobal.net>    wrote:
>>>> On 1/2/2011 6:26 PM, justaguy wrote:
>>
>>>>> 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
>>
>>>> You do not need execute privileges to write the file - in fact, you
>>>> should NOT have it - the file is not an executable.  You also definitely
>>>> should NOT have global write (or read) privileges.
>>
>>>> Did you check the return value from fopen()?  ALWAYS check it to ensure
>>>> that the file opened correctly.  Also, do you know if the fread() and/or
>>>> fwrite() worked correctly?  You never check to see.
>>
>>>> --
>>>> ==================
>>>> Remove the "x" from my email address
>>>> Jerry Stuckle
>>>> JDS Computer Training Corp.
>>>> jstuck...@attglobal.net
>>>> ==================
>>
>>> Jerry,
>>
>>> Here's the block of code with debugging info and it still has a
>>> problem:
>>> //insert votes to txt file
>>> $insertvote = $yes."||".$no;
>>> $fp = fopen($filename,"w");
>>> echo "fp;";
>>> echo $fp;
>>
>>> fputs($fp,$insertvote);
>>> echo "insert; ";
>>> echo $insertvote;
>>> fclose($fp);
>>
>>> And here's its output:
>>> 10 fp;insert; 1||0
>>
>>> Which seems to suggest the operation of $fp = fopen($filename,"w")
>>> failed.
>>
>>> // the poll_result.txt file is in the same directory
>>> $filename = "poll_result.txt";
>>
>>> /* why ok with another php script?
>>> Why a similar statement for file read in another script is ok.
>>> $myFile = "someLog.txt";
>>> */
>>
>>> And yes, I know the 'x' bit isn't necessary.  Odd.   Thanks.
>>
>> I'm not talking about 'debug code' - I'm talking about actual code you
>> should have in every script - error checking.
>>
>> NEVER assume an external operation works. You should ALWAYS check the
>> return code, especially where external operations are concerned, and if
>> you get a bad one, you should take correct action.
>>
>> fopen() returns false if the file was not opened.  So your current
>> example should have checked for a failure in fopen and taken the
>> appropriate action.  For testing purposes, displaying a message would be
>> sufficient.  You would not want to do that on a production server, of
>> course, but you should at least log the error.
>>
>> Had you had such code in place, you would have known that the fopen()
>> failed and could have followed down why.  And if this is your
>> development server, you should have in your php.ini:
>>
>> display_errors=on
>> error_reporting=E_ALL  (or E_ALL | E_STRICT)
>>
>> These would have given you additional messages. But you don't want these
>> on a production server; instead you should log your PHP errors to a file
>> and look at that file when you have problems.
>>
>> --
>> ==================
>> Remove the "x" from my email address
>> Jerry Stuckle
>> JDS Computer Training Corp.
>> jstuck...@attglobal.net
>> ==================
>
> Jerry,
>
> The code isn't working, so, of course it's not in production.  I'm
> using an ISP's server, don't have a lot of control...
> yes, you're right, I was lazy in error detection/tracking for this
> piece of code, thought it should be fairly straight-forward.
>
> Thanks.
>
> Don

Another point - get your own development machine going. It will make 
your life a lot easier.  Even if it's not the same OS and won't catch 
every error (i.e. you wouldn't see this error on Windows), it will help 
you many other ways.

And depending on the ISP's setup, ini_set() and/or your .htaccess file 
can change a number of PHP settings for a single script, every script on 
your site, or many steps in between.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
0
jstucklex (14659)
1/3/2011 3:22:48 AM
On 02/01/11 23:56, Jerry Stuckle wrote:

> Like the original op's, your code is totally unsafe in a multitasking
> environment.

I didn't say it was. I just took his code and made it work on my dev
server. It's up to him to make sure his code is robust for the
environment he's running it in.

As my dev server isn't a multitasking environment from the point of view
of multiple users accessing the poll at once, I'm not too worried about
whether this particular code on it is robust in that environment.

Rgds

Denis McMahon
0
1/3/2011 3:38:50 AM
On 1/2/2011 10:38 PM, Denis McMahon wrote:
> On 02/01/11 23:56, Jerry Stuckle wrote:
>
>> Like the original op's, your code is totally unsafe in a multitasking
>> environment.
>
> I didn't say it was. I just took his code and made it work on my dev
> server. It's up to him to make sure his code is robust for the
> environment he's running it in.
>
> As my dev server isn't a multitasking environment from the point of view
> of multiple users accessing the poll at once, I'm not too worried about
> whether this particular code on it is robust in that environment.
>
> Rgds
>
> Denis McMahon

No, but if you're going to suggest code, you need to suggest good code 
or list major limitations like not being safe in a multitasking environment.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
0
jstucklex (14659)
1/3/2011 3:46:14 AM
On Jan 2, 10:22=A0pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> On 1/2/2011 9:13 PM, justaguy wrote:
>
>
>
> > On Jan 2, 8:34 pm, Jerry Stuckle<jstuck...@attglobal.net> =A0wrote:
> >> On 1/2/2011 8:04 PM, justaguy wrote:
>
> >>> On Jan 2, 6:55 pm, Jerry Stuckle<jstuck...@attglobal.net> =A0 =A0wrot=
e:
> >>>> On 1/2/2011 6:26 PM, justaguy wrote:
>
> >>>>> 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. =A0Added 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. =A0Why?
>
> >>>>>> The following seems to work for me.
>
> >>>>>> <?php
> >>>>>> $filename =3D "poll_result.txt";
> >>>>>> if (isset($_POST['vote'])) {
> >>>>>> =A0 =A0 =A0$vote =3D intval($_POST['vote']); // get this vote
> >>>>>> =A0 =A0 =A0$content =3D file($filename); // read result file
> >>>>>> =A0 =A0 =A0$array =3D explode("||", $content[0]);
> >>>>>> =A0 =A0 =A0$yes =3D intval($array[0]); // get stored results
> >>>>>> =A0 =A0 =A0$no =3D intval($array[1]);
> >>>>>> =A0 =A0 =A0if ($vote =3D=3D 1) $yes++; // increment one
> >>>>>> =A0 =A0 =A0if ($vote =3D=3D 0) $no++;
> >>>>>> =A0 =A0 =A0$insertvote =3D $yes."||".$no; // new result string
> >>>>>> =A0 =A0 =A0}
> >>>>>> else {
> >>>>>> =A0 =A0 =A0$insertvote =3D "0||0\n"; // reset result string
> >>>>>> =A0 =A0 =A0$yes =3D 0;
> >>>>>> =A0 =A0 =A0$no =3D 0;
> >>>>>> =A0 =A0 =A0}
> >>>>>> $fp =3D 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=3D"padding:1em 3em">
> >>>>>> <form method=3D"post" action=3D"quickpoll.php" name=3D"f1" id=3D"f=
1">
> >>>>>> <p>Yes:<input type=3D"radio" name=3D"vote" id=3D"v1_1" value=3D"1"=
><br>
> >>>>>> No:<input type=3D"radio" name=3D"vote" id=3D"v1_0" value=3D"0"><br=
>
> >>>>>> <input type=3D"submit" value=3D"Vote Now" name=3D"s1" id=3D"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. =A0The other target text file has rwxrwxrwx attributes whi=
le
> >>>>> this one has rwrwrw attributes. =A0I thought the global writable wo=
uld
> >>>>> suffice but it seems I was incorrect. =A0My ftp client failed to do
> >>>>> chmod 755 to the global x (execute) attribute to the file.
>
> >>>>> Thanks though.
>
> >>>>> Don
>
> >>>> You do not need execute privileges to write the file - in fact, you
> >>>> should NOT have it - the file is not an executable. =A0You also defi=
nitely
> >>>> should NOT have global write (or read) privileges.
>
> >>>> Did you check the return value from fopen()? =A0ALWAYS check it to e=
nsure
> >>>> that the file opened correctly. =A0Also, do you know if the fread() =
and/or
> >>>> fwrite() worked correctly? =A0You never check to see.
>
> >>>> --
> >>>> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> >>>> Remove the "x" from my email address
> >>>> Jerry Stuckle
> >>>> JDS Computer Training Corp.
> >>>> jstuck...@attglobal.net
> >>>> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
>
> >>> Jerry,
>
> >>> Here's the block of code with debugging info and it still has a
> >>> problem:
> >>> //insert votes to txt file
> >>> $insertvote =3D $yes."||".$no;
> >>> $fp =3D fopen($filename,"w");
> >>> echo "fp;";
> >>> echo $fp;
>
> >>> fputs($fp,$insertvote);
> >>> echo "insert; ";
> >>> echo $insertvote;
> >>> fclose($fp);
>
> >>> And here's its output:
> >>> 10 fp;insert; 1||0
>
> >>> Which seems to suggest the operation of $fp =3D fopen($filename,"w")
> >>> failed.
>
> >>> // the poll_result.txt file is in the same directory
> >>> $filename =3D "poll_result.txt";
>
> >>> /* why ok with another php script?
> >>> Why a similar statement for file read in another script is ok.
> >>> $myFile =3D "someLog.txt";
> >>> */
>
> >>> And yes, I know the 'x' bit isn't necessary. =A0Odd. =A0 Thanks.
>
> >> I'm not talking about 'debug code' - I'm talking about actual code you
> >> should have in every script - error checking.
>
> >> NEVER assume an external operation works. You should ALWAYS check the
> >> return code, especially where external operations are concerned, and i=
f
> >> you get a bad one, you should take correct action.
>
> >> fopen() returns false if the file was not opened. =A0So your current
> >> example should have checked for a failure in fopen and taken the
> >> appropriate action. =A0For testing purposes, displaying a message woul=
d be
> >> sufficient. =A0You would not want to do that on a production server, o=
f
> >> course, but you should at least log the error.
>
> >> Had you had such code in place, you would have known that the fopen()
> >> failed and could have followed down why. =A0And if this is your
> >> development server, you should have in your php.ini:
>
> >> display_errors=3Don
> >> error_reporting=3DE_ALL =A0(or E_ALL | E_STRICT)
>
> >> These would have given you additional messages. But you don't want the=
se
> >> on a production server; instead you should log your PHP errors to a fi=
le
> >> and look at that file when you have problems.
>
> >> --
> >> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> >> Remove the "x" from my email address
> >> Jerry Stuckle
> >> JDS Computer Training Corp.
> >> jstuck...@attglobal.net
> >> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
>
> > Jerry,
>
> > The code isn't working, so, of course it's not in production. =A0I'm
> > using an ISP's server, don't have a lot of control...
> > yes, you're right, I was lazy in error detection/tracking for this
> > piece of code, thought it should be fairly straight-forward.
>
> > Thanks.
>
> > Don
>
> Another point - get your own development machine going. It will make
> your life a lot easier. =A0Even if it's not the same OS and won't catch
> every error (i.e. you wouldn't see this error on Windows), it will help
> you many other ways.
>
> And depending on the ISP's setup, ini_set() and/or your .htaccess file
> can change a number of PHP settings for a single script, every script on
> your site, or many steps in between.
>
> --
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck...@attglobal.net
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D

Too bad, an open source webserver, Caucho Resin on my Windows 7 box
fails to support php.  The same code produced a blank page with
nothing.
0
donli (155)
1/3/2011 4:29:16 AM
Gazing into my crystal ball I observed justaguy <donli@yahoo.com>
writing in
news:ccc49c8d-262f-4b86-a1d6-4ef388fe677e@p7g2000prb.googlegroups.com: 

> On Jan 2, 10:22�pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:
>> On 1/2/2011 9:13 PM, justaguy wrote:
>>
>>
>>
>> > On Jan 2, 8:34 pm, Jerry Stuckle<jstuck...@attglobal.net> �wrote:
>> >> On 1/2/2011 8:04 PM, justaguy wrote:
>>
>> >>> On Jan 2, 6:55 pm, Jerry Stuckle<jstuck...@attglobal.net> � �wrot
> e:
>> >>>> On 1/2/2011 6:26 PM, justaguy wrote:
>>
>> >>>>> 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="f
> 1">
>> >>>>>> <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 whi 
> le
>> >>>>> this one has rwrwrw attributes. �I thought the global writable
>> >>>>> wo 
> uld
>> >>>>> 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
>>
>> >>>> You do not need execute privileges to write the file - in fact,
>> >>>> you should NOT have it - the file is not an executable. �You
>> >>>> also defi 
> nitely
>> >>>> should NOT have global write (or read) privileges.
>>
>> >>>> Did you check the return value from fopen()? �ALWAYS check it to
>> >>>> e 
> nsure
>> >>>> that the file opened correctly. �Also, do you know if the
>> >>>> fread() 
> and/or
>> >>>> fwrite() worked correctly? �You never check to see.
>>
>> >>>> --
>> >>>> =================
>> >>>> Remove the "x" from my email address
>> >>>> Jerry Stuckle
>> >>>> JDS Computer Training Corp.
>> >>>> jstuck...@attglobal.net
>> >>>> =================
>>
>> >>> Jerry,
>>
>> >>> Here's the block of code with debugging info and it still has a
>> >>> problem:
>> >>> //insert votes to txt file
>> >>> $insertvote = $yes."||".$no;
>> >>> $fp = fopen($filename,"w");
>> >>> echo "fp;";
>> >>> echo $fp;
>>
>> >>> fputs($fp,$insertvote);
>> >>> echo "insert; ";
>> >>> echo $insertvote;
>> >>> fclose($fp);
>>
>> >>> And here's its output:
>> >>> 10 fp;insert; 1||0
>>
>> >>> Which seems to suggest the operation of $fp =
>> >>> fopen($filename,"w") failed.
>>
>> >>> // the poll_result.txt file is in the same directory
>> >>> $filename = "poll_result.txt";
>>
>> >>> /* why ok with another php script?
>> >>> Why a similar statement for file read in another script is ok.
>> >>> $myFile = "someLog.txt";
>> >>> */
>>
>> >>> And yes, I know the 'x' bit isn't necessary. �Odd. � Thanks.
>>
>> >> I'm not talking about 'debug code' - I'm talking about actual code
>> >> you should have in every script - error checking.
>>
>> >> NEVER assume an external operation works. You should ALWAYS check
>> >> the return code, especially where external operations are
>> >> concerned, and i 
> f
>> >> you get a bad one, you should take correct action.
>>
>> >> fopen() returns false if the file was not opened. �So your current
>> >> example should have checked for a failure in fopen and taken the
>> >> appropriate action. �For testing purposes, displaying a message
>> >> woul 
> d be
>> >> sufficient. �You would not want to do that on a production server,
>> >> o 
> f
>> >> course, but you should at least log the error.
>>
>> >> Had you had such code in place, you would have known that the
>> >> fopen() failed and could have followed down why. �And if this is
>> >> your development server, you should have in your php.ini:
>>
>> >> display_errors=on
>> >> error_reporting=E_ALL �(or E_ALL | E_STRICT)
>>
>> >> These would have given you additional messages. But you don't want
>> >> the 
> se
>> >> on a production server; instead you should log your PHP errors to
>> >> a fi 
> le
>> >> and look at that file when you have problems.
>>
>> >> --
>> >> =================
>> >> Remove the "x" from my email address
>> >> Jerry Stuckle
>> >> JDS Computer Training Corp.
>> >> jstuck...@attglobal.net
>> >> =================
>>
>> > Jerry,
>>
>> > The code isn't working, so, of course it's not in production. �I'm
>> > using an ISP's server, don't have a lot of control...
>> > yes, you're right, I was lazy in error detection/tracking for this
>> > piece of code, thought it should be fairly straight-forward.
>>
>> > Thanks.
>>
>> > Don
>>
>> Another point - get your own development machine going. It will make
>> your life a lot easier. �Even if it's not the same OS and won't catch
>> every error (i.e. you wouldn't see this error on Windows), it will
>> help you many other ways.
>>
>> And depending on the ISP's setup, ini_set() and/or your .htaccess
>> file can change a number of PHP settings for a single script, every
>> script on your site, or many steps in between.
>>
>> --
>> =================
>> Remove the "x" from my email address
>> Jerry Stuckle
>> JDS Computer Training Corp.
>> jstuck...@attglobal.net
>> =================
> 
> Too bad, an open source webserver, Caucho Resin on my Windows 7 box
> fails to support php.  The same code produced a blank page with
> nothing.
> 

What edition of Win7?  If it's not Home, you could use IIS.

-- 
Adrienne Boswell at Home
Arbpen Web Site Design Services
http://www.cavalcade-of-coding.info
Please respond to the group so others can share
0
arbpen454 (114)
1/3/2011 6:36:08 AM
On 1/2/2011 11:29 PM, justaguy wrote:
>>
>>> Jerry,
>>
>>> The code isn't working, so, of course it's not in production.  I'm
>>> using an ISP's server, don't have a lot of control...
>>> yes, you're right, I was lazy in error detection/tracking for this
>>> piece of code, thought it should be fairly straight-forward.
>>
>>> Thanks.
>>
>>> Don
>>
>> Another point - get your own development machine going. It will make
>> your life a lot easier.  Even if it's not the same OS and won't catch
>> every error (i.e. you wouldn't see this error on Windows), it will help
>> you many other ways.
>>
>> And depending on the ISP's setup, ini_set() and/or your .htaccess file
>> can change a number of PHP settings for a single script, every script on
>> your site, or many steps in between.
>>
>
> Too bad, an open source webserver, Caucho Resin on my Windows 7 box
> fails to support php.  The same code produced a blank page with
> nothing.

Why don't you just install Apache - it's open source, free and supports 
PHP just fine.   It also happens to be the most used web server in the 
world.

And BTW - I didn't say the code was "in production".  I said it was "on 
a production machine".  Two entirely different things.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
0
jstucklex (14659)
1/3/2011 11:53:45 AM
On 03/01/11 03:46, Jerry Stuckle wrote:

> No, but if you're going to suggest code, you need to suggest good code
> or list major limitations like not being safe in a multitasking
> environment.

I see no point in voicing issues you've already mentioned Jerry.

Rgds

Denis McMahon
0
1/3/2011 1:36:07 PM
On 03/01/11 04:29, justaguy wrote:

> Too bad, an open source webserver, Caucho Resin on my Windows 7 box
> fails to support php.  The same code produced a blank page with
> nothing.

If you want a PHP / MySQL / Apache setup on a windows box for code
development, check out http://www.wampserver.com

Rgds

Denis McMahon
0
1/3/2011 1:38:39 PM
On Jan 3, 6:53=A0am, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> On 1/2/2011 11:29 PM, justaguy wrote:
>
>
>
>
>
> >>> Jerry,
>
> >>> The code isn't working, so, of course it's not in production. =A0I'm
> >>> using an ISP's server, don't have a lot of control...
> >>> yes, you're right, I was lazy in error detection/tracking for this
> >>> piece of code, thought it should be fairly straight-forward.
>
> >>> Thanks.
>
> >>> Don
>
> >> Another point - get your own development machine going. It will make
> >> your life a lot easier. =A0Even if it's not the same OS and won't catc=
h
> >> every error (i.e. you wouldn't see this error on Windows), it will hel=
p
> >> you many other ways.
>
> >> And depending on the ISP's setup, ini_set() and/or your .htaccess file
> >> can change a number of PHP settings for a single script, every script =
on
> >> your site, or many steps in between.
>
> > Too bad, an open source webserver, Caucho Resin on my Windows 7 box
> > fails to support php. =A0The same code produced a blank page with
> > nothing.
>
> Why don't you just install Apache - it's open source, free and supports
> PHP just fine. =A0 It also happens to be the most used web server in the
> world.
>
> And BTW - I didn't say the code was "in production". =A0I said it was "on
> a production machine". =A0Two entirely different things.
>
> --
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck...@attglobal.net
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D

Hi all, problem resolved with the same (my 'original' code).  My ISP
first adversely changed file attributes of another text file,
Terrible!  Which failed my software download routine, anyway, after
calling them up and instructing them to set it to rw rw rw, all's well
now.

But let me ask Jerry and all, how do we ensure the "target file" to
support concurrent users, if it's opened by user A, we need to lock it
or something... how do we do it with php?

Many thanks.

Don
0
donli (155)
1/3/2011 11:11:16 PM
On Jan 3, 8:38=A0am, Denis McMahon <denis.m.f.mcma...@googlemail.com>
wrote:
> On 03/01/11 04:29, justaguy wrote:
>
> > Too bad, an open source webserver, Caucho Resin on my Windows 7 box
> > fails to support php. =A0The same code produced a blank page with
> > nothing.
>
> If you want a PHP / MySQL / Apache setup on a windows box for code
> development, check outhttp://www.wampserver.com
>
> Rgds
>
> Denis McMahon

I can't, Denis, if I do it must mirror what my ISP has.  Thanks
though.  Don
0
donli (155)
1/3/2011 11:12:03 PM
On 1/3/2011 6:11 PM, justaguy wrote:
> On Jan 3, 6:53 am, Jerry Stuckle<jstuck...@attglobal.net>  wrote:
>> On 1/2/2011 11:29 PM, justaguy wrote:
>>
>>
>>
>>
>>
>>>>> Jerry,
>>
>>>>> The code isn't working, so, of course it's not in production.  I'm
>>>>> using an ISP's server, don't have a lot of control...
>>>>> yes, you're right, I was lazy in error detection/tracking for this
>>>>> piece of code, thought it should be fairly straight-forward.
>>
>>>>> Thanks.
>>
>>>>> Don
>>
>>>> Another point - get your own development machine going. It will make
>>>> your life a lot easier.  Even if it's not the same OS and won't catch
>>>> every error (i.e. you wouldn't see this error on Windows), it will help
>>>> you many other ways.
>>
>>>> And depending on the ISP's setup, ini_set() and/or your .htaccess file
>>>> can change a number of PHP settings for a single script, every script on
>>>> your site, or many steps in between.
>>
>>> Too bad, an open source webserver, Caucho Resin on my Windows 7 box
>>> fails to support php.  The same code produced a blank page with
>>> nothing.
>>
>> Why don't you just install Apache - it's open source, free and supports
>> PHP just fine.   It also happens to be the most used web server in the
>> world.
>>
>> And BTW - I didn't say the code was "in production".  I said it was "on
>> a production machine".  Two entirely different things.
>>
>
> Hi all, problem resolved with the same (my 'original' code).  My ISP
> first adversely changed file attributes of another text file,
> Terrible!  Which failed my software download routine, anyway, after
> calling them up and instructing them to set it to rw rw rw, all's well
> now.
>
> But let me ask Jerry and all, how do we ensure the "target file" to
> support concurrent users, if it's opened by user A, we need to lock it
> or something... how do we do it with php?
>
> Many thanks.
>
> Don

It should NOT be world writable, which is one security exposure. 
Another is that anyone can download the file at any time, because it's 
in your web site's root directory.  Both are bad.  At the very least you 
should protect access through .htaccess, and better is to have it 
outside your web site's root.

You can single thread access on some OS's - see flock() in the PHP 
documentation.  But better is to use a database, which will solve all 
these problems.


-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
0
jstucklex (14659)
1/4/2011 12:37:44 AM
On 1/3/2011 6:12 PM, justaguy wrote:
> On Jan 3, 8:38 am, Denis McMahon<denis.m.f.mcma...@googlemail.com>
> wrote:
>> On 03/01/11 04:29, justaguy wrote:
>>
>>> Too bad, an open source webserver, Caucho Resin on my Windows 7 box
>>> fails to support php.  The same code produced a blank page with
>>> nothing.
>>
>> If you want a PHP / MySQL / Apache setup on a windows box for code
>> development, check outhttp://www.wampserver.com
>>
>> Rgds
>>
>> Denis McMahon
>
> I can't, Denis, if I do it must mirror what my ISP has.  Thanks
> though.  Don

Not a problem, if you code your scripts correctly.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
0
jstucklex (14659)
1/4/2011 12:38:36 AM
justaguy wrote:
> On Jan 3, 6:53 am, Jerry Stuckle <jstuck...@attglobal.net> wrote:
>> On 1/2/2011 11:29 PM, justaguy wrote:
>>
>>
>>
>>
>>
>>>>> Jerry,
>>>>> The code isn't working, so, of course it's not in production.  I'm
>>>>> using an ISP's server, don't have a lot of control...
>>>>> yes, you're right, I was lazy in error detection/tracking for this
>>>>> piece of code, thought it should be fairly straight-forward.
>>>>> Thanks.
>>>>> Don
>>>> Another point - get your own development machine going. It will make
>>>> your life a lot easier.  Even if it's not the same OS and won't catch
>>>> every error (i.e. you wouldn't see this error on Windows), it will help
>>>> you many other ways.
>>>> And depending on the ISP's setup, ini_set() and/or your .htaccess file
>>>> can change a number of PHP settings for a single script, every script on
>>>> your site, or many steps in between.
>>> Too bad, an open source webserver, Caucho Resin on my Windows 7 box
>>> fails to support php.  The same code produced a blank page with
>>> nothing.
>> Why don't you just install Apache - it's open source, free and supports
>> PHP just fine.   It also happens to be the most used web server in the
>> world.
>>
>> And BTW - I didn't say the code was "in production".  I said it was "on
>> a production machine".  Two entirely different things.
>>
>> --
>> ==================
>> Remove the "x" from my email address
>> Jerry Stuckle
>> JDS Computer Training Corp.
>> jstuck...@attglobal.net
>> ==================
> 
> Hi all, problem resolved with the same (my 'original' code).  My ISP
> first adversely changed file attributes of another text file,
> Terrible!  Which failed my software download routine, anyway, after
> calling them up and instructing them to set it to rw rw rw, all's well
> now.
> 
> But let me ask Jerry and all, how do we ensure the "target file" to
> support concurrent users, if it's opened by user A, we need to lock it
> or something... how do we do it with php?
> 
> Many thanks.
> 
> Don
create a lock file
0
tnp (2409)
1/4/2011 4:16:53 AM
On Jan 3, 7:37=A0pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> On 1/3/2011 6:11 PM, justaguy wrote:
>
>
>
> > On Jan 3, 6:53 am, Jerry Stuckle<jstuck...@attglobal.net> =A0wrote:
> >> On 1/2/2011 11:29 PM, justaguy wrote:
>
> >>>>> Jerry,
>
> >>>>> The code isn't working, so, of course it's not in production. =A0I'=
m
> >>>>> using an ISP's server, don't have a lot of control...
> >>>>> yes, you're right, I was lazy in error detection/tracking for this
> >>>>> piece of code, thought it should be fairly straight-forward.
>
> >>>>> Thanks.
>
> >>>>> Don
>
> >>>> Another point - get your own development machine going. It will make
> >>>> your life a lot easier. =A0Even if it's not the same OS and won't ca=
tch
> >>>> every error (i.e. you wouldn't see this error on Windows), it will h=
elp
> >>>> you many other ways.
>
> >>>> And depending on the ISP's setup, ini_set() and/or your .htaccess fi=
le
> >>>> can change a number of PHP settings for a single script, every scrip=
t on
> >>>> your site, or many steps in between.
>
> >>> Too bad, an open source webserver, Caucho Resin on my Windows 7 box
> >>> fails to support php. =A0The same code produced a blank page with
> >>> nothing.
>
> >> Why don't you just install Apache - it's open source, free and support=
s
> >> PHP just fine. =A0 It also happens to be the most used web server in t=
he
> >> world.
>
> >> And BTW - I didn't say the code was "in production". =A0I said it was =
"on
> >> a production machine". =A0Two entirely different things.
>
> > Hi all, problem resolved with the same (my 'original' code). =A0My ISP
> > first adversely changed file attributes of another text file,
> > Terrible! =A0Which failed my software download routine, anyway, after
> > calling them up and instructing them to set it to rw rw rw, all's well
> > now.
>
> > But let me ask Jerry and all, how do we ensure the "target file" to
> > support concurrent users, if it's opened by user A, we need to lock it
> > or something... how do we do it with php?
>
> > Many thanks.
>
> > Don
>
> It should NOT be world writable, which is one security exposure.
> Another is that anyone can download the file at any time, because it's
> in your web site's root directory. =A0Both are bad. =A0At the very least =
you
> should protect access through .htaccess, and better is to have it
> outside your web site's root.
>
> You can single thread access on some OS's - see flock() in the PHP
> documentation. =A0But better is to use a database, which will solve all
> these problems.
>
> --
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck...@attglobal.net
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D


"
It should NOT be world writable,
"
world writable means to let Internet users to write to it, so, the
global w attribute is removed, how could an anonymous user
write to it?


"and better is to have it outside your web site's root. "
Yes, for now it's for dev purpose, so, I didn't care.

"
You can single thread access on some OS's - see flock() in the PHP
documentation.
"
sample code?  Since I'm not a php coder and don't intend to become
one, at least not now... could you save me some time?

"
But better is to use a database, which will solve all these problems.
"
No, not practical, this is a temp task (a poll).

Thanks.

0
donli (155)
1/5/2011 3:19:55 AM
On 1/4/2011 10:19 PM, justaguy wrote:
> On Jan 3, 7:37 pm, Jerry Stuckle<jstuck...@attglobal.net>  wrote:
>> On 1/3/2011 6:11 PM, justaguy wrote:
>>
>>
>>
>>> On Jan 3, 6:53 am, Jerry Stuckle<jstuck...@attglobal.net>    wrote:
>>>> On 1/2/2011 11:29 PM, justaguy wrote:
>>
>>>>>>> Jerry,
>>
>>>>>>> The code isn't working, so, of course it's not in production.  I'm
>>>>>>> using an ISP's server, don't have a lot of control...
>>>>>>> yes, you're right, I was lazy in error detection/tracking for this
>>>>>>> piece of code, thought it should be fairly straight-forward.
>>
>>>>>>> Thanks.
>>
>>>>>>> Don
>>
>>>>>> Another point - get your own development machine going. It will make
>>>>>> your life a lot easier.  Even if it's not the same OS and won't catch
>>>>>> every error (i.e. you wouldn't see this error on Windows), it will help
>>>>>> you many other ways.
>>
>>>>>> And depending on the ISP's setup, ini_set() and/or your .htaccess file
>>>>>> can change a number of PHP settings for a single script, every script on
>>>>>> your site, or many steps in between.
>>
>>>>> Too bad, an open source webserver, Caucho Resin on my Windows 7 box
>>>>> fails to support php.  The same code produced a blank page with
>>>>> nothing.
>>
>>>> Why don't you just install Apache - it's open source, free and supports
>>>> PHP just fine.   It also happens to be the most used web server in the
>>>> world.
>>
>>>> And BTW - I didn't say the code was "in production".  I said it was "on
>>>> a production machine".  Two entirely different things.
>>
>>> Hi all, problem resolved with the same (my 'original' code).  My ISP
>>> first adversely changed file attributes of another text file,
>>> Terrible!  Which failed my software download routine, anyway, after
>>> calling them up and instructing them to set it to rw rw rw, all's well
>>> now.
>>
>>> But let me ask Jerry and all, how do we ensure the "target file" to
>>> support concurrent users, if it's opened by user A, we need to lock it
>>> or something... how do we do it with php?
>>
>>> Many thanks.
>>
>>> Don
>>
>> It should NOT be world writable, which is one security exposure.
>> Another is that anyone can download the file at any time, because it's
>> in your web site's root directory.  Both are bad.  At the very least you
>> should protect access through .htaccess, and better is to have it
>> outside your web site's root.
>>
>> You can single thread access on some OS's - see flock() in the PHP
>> documentation.  But better is to use a database, which will solve all
>> these problems.
>>
>
>
> "
> It should NOT be world writable,
> "
> world writable means to let Internet users to write to it, so, the
> global w attribute is removed, how could an anonymous user
> write to it?
>

No, world writable means anyone else on that server can write to it - 
including other users.  You may have 150 web sites on a shared server, 
with each web site having its own users.  Any of them can overwrite your 
file.

>
> "and better is to have it outside your web site's root."
> Yes, for now it's for dev purpose, so, I didn't care.
>

Doesn't matter.  If you start with good habits, you have fewer problems 
later.

> "
> You can single thread access on some OS's - see flock() in the PHP
> documentation.
> "
> sample code?  Since I'm not a php coder and don't intend to become
> one, at least not now... could you save me some time?
>

At my normal consulting rates, I can.  This newsgroup is for users 
helping users, not free consulting.

> "
> But better is to use a database, which will solve all these problems.
> "
> No, not practical, this is a temp task (a poll).
>
> Thanks.
>

Still better to use a database - and completely practical.


-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
0
jstucklex (14659)
1/5/2011 3:54:21 AM
On 05/01/11 03:19, justaguy wrote:

> "
> It should NOT be world writable,
> "
> world writable means to let Internet users to write to it, so, the
> global w attribute is removed, how could an anonymous user
> write to it?

No. The file system access attributes control access for the server file
system. Internet users are not logged on to the server as users. The web
server process is the user that is accessing the file.

eg If your web server process runs as user www_data then www_data will
be the owner of any file it creates, and will only need owner rw access
to read and write the file.

> "
> You can single thread access on some OS's - see flock() in the PHP
> documentation.
> "
> sample code?  Since I'm not a php coder and don't intend to become
> one, at least not now... could you save me some time?

There's usually plenty of code examples in the user added notes to the
php manual. Go read.

> "
> But better is to use a database, which will solve all these problems.
> "
> No, not practical, this is a temp task (a poll).

The database functionality may already be there, simply waiting for you
to take advantage of it.

Rgds

Denis McMahon
0
1/5/2011 8:47:07 AM
On 05/01/11 03:19, justaguy wrote:

> "
> You can single thread access on some OS's - see flock() in the PHP
> documentation.
> "
> sample code?  Since I'm not a php coder and don't intend to become
> one, at least not now... could you save me some time?

This isn't perfect, but should allow you to output votes to a file that
you can tally later. If the file can't be seized for append, it backs
off up to 10 times for a random interval of 0.1 +- 0.05 secs and tries
again. It may be more robust than your approach. Doubtless others here
will pick it apart, but they prefer to do that rather than offer solutions.

<?php

// Use one of these file names as appropriate to your setup
$file = "/home/justaguy/path/poll_result.log";
$file = "data/poll_result.log";
$file = "poll_result.log";

$v = "no";
if ($vote == 1) $v = "yes";
$info = $_SERVER['REMOTE_ADDR'] . " " . date(DATE_RFC2822);

$vstr = $v . " " . $info . "\n";

$tries = 10;
while (!$fh = @fopen($file,"a") && $tries--) usleep(rand(50000,150000));
if ($fh) {
  fwrite($fh,$vstr);
  fclose($fh);
}
else {
  error_log($info . ' open poll_result.log for append failed.');
}

?>

If after 10 attempts it still fails, it puts a message in wherever the
error log is defined as.

Code to open, read and tally the votes is left as an exercise for the OP.

Note, however, that this won't solve your original problem, which seems
to be that the process that is executing the php doesn't have write
access to the directory that the file is being created in.

Rgds

Denis McMahon
0
1/5/2011 1:00:08 PM
Reply:

Similar Artilces:

PHP fails writing to text file?
Hello I'm stumped as to why PHP fails writing into a text file, with the script being called through Apache: ============== # pwd /usr/local/www/data/ ============== # ll -rwxr--r-- 1 root wheel 499 Jan 15 04:59 index.php ============== # cat /usr/local/etc/apache/httpd.conf User www Group www #BAD User root #BAD Group wheel ============== <?php $fp = fopen("test.txt", "w"); fputs($fp,"First line\r\n"); fwrite($fp,"Second line\r\n"); fclose($fp); ?> ============== http://localhost/ ============== # l...

concatenating multiple text files into one text file
Hello all, I have a huge number of text files like : spectrum1_300_315.csv spectrum1_315_331.csv spectrum1_331_364.csv spectrum1_364_386.csv spectrum1_386_401.csv ...................................... ....................................... each file contains some headerlines at the beginning and data in 2 columns. I want to concatenate the data of the files into one text file .Can anyone hel me pls?thank u in advance. ...

Converting A Unicode Text File to An ASCII Text File
We have a large number of text files built in Unicode that we need to be read by SAS. SAS does not read Unicode text. To convert the Unicode text to ASCII text we did the following: A Unicode text file adds an additional blank space to each character. To remove this blank character, you can use the code below. The hexidecimal value '00' is a blank character. So remove it using the SAS statement '00'x. The 'x' tells SAS you are reading hexidecimal. Use RECFM=N to tell SAS that you are reading a stream of data that will not conform to a typical file structure. SAS will treat the file as a very long single record. data _null_; infile 'c:\xmlfile.xml' recfm=n; file 'c:\ascifile.txt' recfm=n; input c $1.; if c ne '00'x then put c $1.; run; ...

write into existing file with &quot;write to text file&quot;
Hi all,&nbsp;I have a text file that contains several lines of data (text). Now I would like to replace the first three lines with text coming from a string array.My approach is shown in WriteToFile.vi that is attached.When I am executing this vi (with an empty file), everything seems to be working fine in the first place.The file will contain the following text:oneoneonetwotwotwothreethreethreeNow, when the third element in the array is shortened (lets say to "threethr") before execution,&nbsp; the file will contain&nbsp; the following text:(the file was not emptied before execution)oneoneone twotwotwo threethrthreeHow can I avoid the last line being written? I have made many tests and I could not find a solution.One more example:Lets say we have an existing file, inside this file is:oneoneone twotwotwo three fourfourfourNow I would like to overwrite line three with "threethreethree". Therefore I execute my vi as shown in the attachment.What I get as a result is:oneoneonetwotwotwothreethreethreeurSo, the text in line four, which should not be touched, is "ur" instead of "fourfourfour". Any idea to solve this problem?What I basically need is replacing a line of a text file in a conveinient way.Thanks,Holger----LV 8.5.1 WriteToFile1.jpg: http://forums.ni.com/attachments/ni/170/327029/1/WriteToFile1.jpg WriteToFile.vi: http://forums.ni.com/attachments/ni/170/327029/2/WriteToFile.vi The remaining fourth line is there becau...

scanning text file and writing from .txt file
Hi, I have this data in a txt file: time = 0.0000E+00 mat.#= 1012 inten= 0.0000E+00 kinen= 0.0000E+00 eroded_ie= 0.0000E+00 eroded_ke= 0.0000E+00 x-mom= 0.0000E+00 y-mom= 0.0000E+00 z-mom= 0.0000E+00 x-rbv= 0.0000E+00 y-rbv= 0.0000E+00 z-rbv= 0.0000E+00 mat.#= 1013 inten= 0.0000E+00 kinen= 0.0000E+00 eroded_ie= 0.0000E+00 eroded_ke= 0.0000E+00 x-mom= 0.0000E+00 y-mom= 0.0000E+00 z-mom= 0.0000E+00 x-rbv= 0.0000E+00 y-rbv= 0.0000E+00 z-rbv= 0.0000E+00 mat.#= 1014 inten= 0.0000E+00 kinen= 0.0000E+00 eroded_ie= 0.0000E+00 eroded_ke= 0.0000E+00 x-mom= 0.0000E+00 y-mom= 0.0000E+00 z-mom= 0.0000E+00 x-rbv= 0.0000E+00 y-rbv= 0.0000E+00 z-rbv= 0.0000E+00.............. I want to write a code which reads this text line by line and prints the 'mat.#' whose intern=0.0000E+00 On 8/3/2012 6:21 PM, Kunal wrote: > Hi, > I have this data in a txt file: > time = 0.0000E+00 > mat.#= 1012 inten= 0.0000E+00 kinen= 0.0000E+00 eroded_ie= 0.0000E+00 eroded_ke= 0.0000E+00 > x-mom= 0.0000E+00 y-mom= 0.0000E+00 z-mom= 0.0000E+00 > x-rbv= 0.0000E+00 y-rbv= 0.0000E+00 z-rbv= 0.0000E+00 > mat.#= 1013 inten= 0.0000E+00 kinen= 0.0000E+00 eroded_ie= 0.0000E+00 eroded_ke= 0.0000E+00 > x-mom= 0.0000E+00 y-mom= 0.0000E+00 z-mom= 0.0000E+00 > x-rbv= 0.0000E+00 y-rbv= 0...

write binary in text file to excel file
Hi all, I have a few questions regarding writing binary in text file to excel file. 1. How do I specify so that there will 8bits in one cell? 2. When the front bits are zeros, the zeros will not be showed. Eg. 00110101 will be shown as 110101. How to make it take the zeros into account? Thanks alot. Best regards, Jess Try to use cell array of srings such as "00101". Then put this cell array in xlswrite function. ------------------------------------ Maxim Vedenev, Matlab freelancer vedenev@ngs.ru http://simulations.narod.ru/ ...

How to write unicode text from RTF to a text file
I'm posting again a question I have asked previously in a more simple way.. We are using RTF control (memo field in a DBF) to store some unicode description in more than 2 languages (this is for a real estate app that describes a property in more than 2 languages). In order to interface with a site, we need to just create a unicode text (xml) adding some unicode string extracted from this RTF control. So far we didnt manage to achieve this as all txt created with VO is ANSI (of cource..) Can anybody suggest a VO solution to this, or do you think this is impossible? Thanks a...

Re: Converting A Unicode Text File to An ASCII Text File
Mike, SAS does not read Unicode text. It is not true encoding=utf8 exist HTH Andre I tried upon this contents (a french one saved in utf8) but showed here in windows Nom,Adressé "Bob","cité Bergère" "Ann","impasse Dôme" with this code under sas windows options validvarname=any; filename a "z:\utf8.csv" encoding=utf8; PROC IMPORT OUT= WORK.PAPER3 DATAFILE=a DBMS=CSV REPLACE; GETNAMES=YES; DATAROW=2; RUN; the results are Nom Adress� Bob cit� Berg�re Ann impasse D�me But perhaps you have another problem Bachenot a �crit : > We have a large number of text files built in Unicode that we need to > be read by SAS. SAS does not read Unicode text. > To convert the Unicode > text to ASCII text we did the following: > A Unicode text file adds an additional blank space to each character. > To remove this blank character, you can use the code below. > > The hexidecimal value '00' is a blank character. So remove it using > the SAS statement '00'x. The 'x' tells SAS you are reading > hexidecimal. > > Use RECFM=N to tell SAS that you are reading a stream of data that > will not conform to a typical file structure. SAS will treat the file > as a very long single record. > > data _null_; > infile 'c:\xmlfile.xml' recfm=n; > file 'c:\ascifile.txt' recfm=n; > input c $1.; > if c ne '00'x th...

How to format a text file just like the RFC-text files?
I want to make some document go like these, what tools can help? Any help would be nice, thanks! BLIOGRAPHY ........................................... 34 APPENDIX A. EXAMPLES ............................................... 36 B. SIMPLE FIELD PARSING ................................... 40 C. DIFFERENCES FROM RFC #733 .............................. 41 D. ALPHABETICAL LISTING OF SYNTAX RULES ................... 44 August 13, 1982 - i - RFC #822 ^L Standard for ARPA Internet Text Messages PREFACE By 1977, the Arpanet employed several informal standards for the text messages (mail) sent among its host computers. It was felt necessary to codify these practices and provide for those features that seemed imminent. The result of that effort was Request for Comments (RFC) #733, "Standard for the Format of ARPA Network Text Message", by Crocker, Vittal, Pogran, and Henderson. The specification attempted to avoid major changes in existing software, while permitting several new features. The framework severely constrains document tone and appear- ance and is primarily useful for most intra-organization communi- cations and well-structured inter-organization communication. It also can be used for some types of inter-process commun...

Read a non text file
How can i convert a weird looking file to text file. I know the main info is stored in the file which looks like below. "����<t���Jч�ĉTV��y�rr��Ph"e~Wm>�E�0Y'p�=C�&�rؙ�<t�Fx�Zo$�+T��=���H Or�r6�S��m&7<�p�q��� u����w}�jlꥎ+_�����Z�?��v��ȉ�XC R�}�_�׍�:�$)�o}��NʨW\&���I@b�#T�B��8���J��CL�ypr\�]R���p\��S�XRҏ�f&?/��� 2�t�_��x���bG���Z�D�v�s [�"��N�# Ѡ�@)�����h'&%�(�)��c�ͼA ���zUZjLRyu�P̤� ��� �W��e�@1'�(��u-nG��p��2_�� T&�6+� _� d�(1Z�E@���h�F�z �~x�fG���s�b�/-+�@��0�%��6�wu�=��z���Y�0...

read text file through Labview and then write to an excel file
Hello, &nbsp; I am relatively new with using Labview. I was wondering what would be a general method of reading data from a text file (words, sentences, numbers, and etc.) and making Labview write it on an Excel file. &nbsp; Thanks Ivan ...

writing cell containing text and matrix to a text file
Is there a way to write a cell containing text and numerical matrix to a text file? I have the following: values = [1 2 3 4 5 6 7 8 9 10]; cellA={'nameA', values};%this is the cell containing the text and matrix cellA = 'name' [1x10 double] So that the text file row would look something like: nameA 1 2 3 4 5 6 7 8 9 10 Ultimately, I would like to be able to append this with cellB, cellC, etc (all same format as shown above). I tried both dlmwrite and xlswrite without much success. Is there a way to do this? Thanks! Here is an example: ...

write file + input file + write file
Hi, I want to write some latex command to a file (file1), input the file at the end of the document. These command shall write to another file (file2) and at a second run I use the file2. Whatever I have tried nothing works and I don't known why. The goal is to save a set of special commands and run them at the end of the document, because they use some values which are only available at the end! Can anybody please help me with that? Thanks in advance! I should be something like: \begin{document} \usepackage{style} \input{file2} %file exists from a previous run \end{document} style.sty: \newwrite\fileone \openout\fileone=file1.out \newwrite\filetwo \openout\filetwo=file2.out \newcommand{\writetofiletwo}[1]{% \write\filetwo{#1}% } \newcommand{\writetofileone}[1]{% \write\fileone{\writetofiletwo{some text}}% } \AtEndDocument{\closeout\fileone% \input{file1}% \closeout\filetwo% } Problem solved :-) \immediate\closeout before \input was required. greenux wrote: > Hi, > I want to write some latex command to a file (file1), input the file > at the end of the document. These command shall write to another file > (file2) and at a second run I use the file2. > Whatever I have tried nothing works and I don't known why. The goal is > to save a set of special commands and run them at the end of the > document, because they use some values which are only available at the > end! > Can anybody please help me with that? > Thanks in advance! &...

Failed opening required 'PEAR.php' (include_path='F:\www\include') in F:\Program Files\PHP\PEAR\Text\CAPTCHA.php on line 22
Hi, Guys=EF=BC=8Cwhen I run my site ,I got some errors: Warning: require_once(PEAR.php) [function.require-once]: failed to open stream: No such file or directory in F:\Program Files\PHP\PEAR \Text\CAPTCHA.php on line 22 Fatal error: require_once() [function.require]: Failed opening required 'PEAR.php' (include_path=3D'F:\www\include') in F:\Program Files \PHP\PEAR\Text\CAPTCHA.php on line 22 It appears that it cann't find the pear.php ,but i checked my dir,and this file was there,and also I have my php.ini file checked,the include_path=3Dinclude_path=3D".;F:\Program Files\PHP\pear;F:\www \include" ,it looks all right,was there anything I have missed in the config file?Or something wrong ? Wish somebody can help me out. Thanks, Mikay >Warning: require_once(PEAR.php) [function.require-once]: failed to >open stream: No such file or directory in F:\Program Files\PHP\PEAR >\Text\CAPTCHA.php on line 22 >Fatal error: require_once() [function.require]: Failed opening >required 'PEAR.php' (include_path='F:\www\include') in F:\Program Files >\PHP\PEAR\Text\CAPTCHA.php on line 22 So where is the pear.php file? >It appears that it cann't find the pear.php ,but i checked my dir,and >this file was there,and also I have my php.ini file checked,the >include_path=include_path=".;F:\Program Files\PHP\pear;F:\www >\include" ,it looks all right,was there anything I have missed in the >config...

Write Property Bag to Text file in Text format, not binary
Hi all I know that I can persist an object's data using the Property Bag in VB6 and MSDN includes the code sample listed below. However what I want to do is save to the text file in PLAIN TEXT Format, *not* as binary. I want to save the file so that it is human readable in the format: name of the property to save; the value to save (mInterestRate). However all the examples that I have found only show how to output the object as binary. Is it possible to write as plain text? Private pb As PropertyBag ' Declare a PropertyBag object. Private LoanObject As Loan ' Declare a Loan object. Private Sub Form_Unload(Cancel As Integer) Dim varTemp as Variant ' Instantiate the PropertyBag object. Set pb = New PropertyBag ' Save the object to the PropertyBag using WriteProperty. pb.WriteProperty "MyLoanObject", LoanObject ' Assign the Contents of the PropertyBag to a Variant. varTemp = pb.Contents ' Save to a text file. Open "C:\Loandata.txt" For Binary As #1 Put #1, , varTemp Close #1 End Sub Thanks for any help Andrew. It may not be what you are after but I always just set up a text file and write all the variables to a text file. sub form_unload() open "c:\app.path\variables.txt" for output as #1 print #1, loanrate print #1, etc close #1 end sub then in form load you do the reverse. ...

How to write PHP standard output on a text file?
Hi. Using PHP 4.3.11, I want my script not to write standard output on the webpage, but on a textfile. I tried with: [code] $variableName = 44; system("/usr/local/php/bin/php /home/foo/script.php > /home/foo/file.txt", $retval); [/code] But '/home/foo/script.php' doesn't consider $variableName. Is there any way to call '/home/foo/script.php' and make it to write standard output on a textfile? Thank you very much. -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 francescomoi@usa.com wrote: > Is there any way to call '/home/foo/script.php' and m...

read from Text file using VB and Insert into SQL table until eof text file reach
Dear All, my text file like following, a1, b1, c1, d1, e1 a2, b2, c2, d2, e2 a3, b3, c3, d3, e3 a4, b4, c4, d4, e4 ................. and im going to insert this values into SQL Tables with columns, [a, b, c, d, e] how im going to do so? i use below src code to do but i can not get the next line and next line of text file until it finished insert Private Sub mot_Click() 'Shell ("C:\Program Files\Microsoft Office\Office11\MSACCESS.EXE c:\fisherdb. mdb /x ImportOpsNilai") 'frmPicCd.Show Dim db_connect ' Path = App.Path & "\ERP consumable code.xls" Dim objFSO Dim objFile, objTextStream Dim strContent Const ForReading = 1 Dim FileName, IEPath, strC1 As String FileName = "U:\bureport\buops\RepNilai.txt" Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.GetFile(FileName) Set objTextStream = objFile.OpenAsTextStream(ForReading, TristateUseDefault) If objFSO.FileExists(FileName) Then Set objFile = objFSO.OpenTextFile(FileName, ForReading) 'While Not objFile.EOF strC1 = objFile.ReadLine Dim word ReDim word(2) word = Split(strC1, ",") ' Dim t1, t2, t3 As String ' MsgBox RTrim(LTrim(word(44))) ' t1 = Replace(word(0), """", "...

How to know if a file is a text file
Hi all. I'm looking for a way to be able to load a generic file from the system and understand if he is plain text. The mimetype module has some nice methods, but for example it's not working for file without extension. Any suggestion? -- -- luca On Sat, 14 Nov 2009 17:02:29 +0100, Luca Fabbri wrote: > I'm looking for a way to be able to load a generic file from the > system and understand if he is plain text. > The mimetype module has some nice methods, but for example it's not > working for file without extension. > > Any suggestion? You could use th...

Newline in a File Text file
Dear all, I have a text file in the form of 1 2 3 4 5 6 --------/--------/--------/--------/--------/--------/ (I just used / to better explain the fields) 6 fields of 8 characters. I want to read lets say fields 4,5 and 6 and then go to the begining of the newline which is in the same format. And then I will test the first character of the newline with $ and if true the read process will terminate. I can read fields by positioning the file pointer with seekg() function. Is there a direct way to position the file pointer to the start of a newlin...

matrix and text to a text file
Hi, I know some similar question have been solved before but I have been reading for a while and I didn't find the answer of my question so, I ask you. I want to create a text-file (.txt) where I will have some text and some matrixs. The format that i want is something like that: -Title- Name1. Name2. power(dbm): big matrix (12000X400) aprox frequency(hz) vector(1x12) aprox So, i created a m-file that can do this writing with fprintf every single character on the file using lots of for loops. It works good but if the matrix is that size it could take a time (about 7 min...

Text file to XML file
I have the following tasks : 1) receive a flat text file which contains data and 2) convert it into an XML The flat text file for example is in this format : 1 2 1234567890123456789012345 where : Column 1 : recordType Column 2 to 8 : companyNumber Column 9 to 14 : batchNumber Column 15 to 22 : hoursTotal Column 23 to 25 : userField After processing, the XML I get will be in this format : <records> <record> <recordType>B</recordType> <companyNumber>1127897</companyNumber> <batchNumber>001234</batchNumber> <hoursTotal>24567809</hoursTotal> <userField>A09</userField> </record> <record> <recordType>B</recordType> <companyNumber>1124183</companyNumber> <batchNumber>091334</batchNumber> <hoursTotal>94857809</hoursTotal> <userField>A08</userField> </record> </records> Now I am a newbie regarding XML, so I was hpoing if somebody can give me the abstract steps involved for this process. Thanks On Fri, 30 Jul 2004 11:55:04 -0400, "Rizwan" <hussains@pendylum.com> wrote: >Now I am a newbie regarding XML, so I was hpoing if somebody can give me the >abstract steps involved for this process. 1. Learn some simple every-purpose scripting language. You might already know on...

One program to read 1000 enscribe file and write to plain text file with same same
have more than 1000 enscribe file along with there DDL's and COBOL library . All I need is to read this file with there corresponding structure and write to Plain file which can be uploaded to Wordpad/notpad. The question is if I use enform then for all this file I have to write enform with there structure ? So 1000 times I have to write enform query for all this file . Moreover ,in my case enform is giving 132 character output . is there any way that I just Input the filename and rest taken care by program like fetching record layout(DDL) and producing simple plain text file. On Ju...

Writing to a text file
Is there a way of creating a seperate text file on a server every time a form is sent? -- � Trigger ? http://www.magic2k.com/ http://www.oddmap.co.uk Neil Trigger wrote: > Is there a way of creating a seperate text file on a server every time a > form is sent? Certainly, but why don't you use a database? A clogged up directory full of thousands of text-files bites you in the end. -- Nobody ever forgets where he buried the hatchet. -- Kin Hubbard Neil Trigger wrote: > Is there a way of creating a seperate text file on a server every > time a form is sen...

write to a text file
hello all this is a really simple question.. but believe me or not i cudnt find a solution to this. whenever i m running the vi, it does run without any problem but when i open the text file where it is suppose to write the data.. the textfile is unreadable. there r some symbols and no numbers. i m attaching the vi. can someone plz tell me where is the problem? regards. writetext.vi: http://forums.ni.com/attachments/ni/170/202881/1/writetext.vi Here it is.. I added carriage returns to make the numbers more readable. There is a better way to do this if you do not have to write to the file ...

Web resources about - Failed to write to a text file (text file is RW) - comp.lang.php

Failed States (album) - Wikipedia, the free encyclopedia
^ Andrews, Alex (August 31, 2012). "Album: Propagandhi - Failed States" . Thrash Hits . Retrieved September 28, 2012 . ^ Okorley, Dre (September ...

The President's Speech Distorts the Truth to Distract From His Failed Record - Facebook
Paul Ryan hat eine Notiz mit dem Titel The President's Speech Distorts the Truth to Distract From His Failed Record geschrieben. Du kannst den ...

Facebook’s Failed Privacy PR Campaign Against Google: An Industry Practice, Poorly Done
In a spectacularly failed attempt at undermining the competition, Facebook has admitted that it hired public relations giant Burson-Marsteller ...

My own spin on the story du jour: Why The Daily failed.
My own spin on the story du jour: Why The Daily failed.

Authorization Failed - LinkedIn
Sorry you are not authorized to perform this action. To find out more please contact LinkedIn customer service .

Business Models : What consumer Internet companies had a large number of users but failed to monetize ...
Answer (1 of 46): I can't think of one. All the companies mentioned here either: a) *Did* have significant revenues: * Netscape (the same ...


Why "Global Warming" Failed & Why Climate Change is Real - YouTube
CLIMATE CHANGE IS VERY REAL - BUT THE OFFICIALS HAVE JEOPARDIZED OUR ABILITY TO PREPARE FOR THE FUTURE Global warming models/predictions have ...

Hotel defends claim it failed to protect staffer in rape case
... has been cleared to file for damages against her former employer in Fujairah. A hotel has defended itself against allegations that it failed ...

Melbourne student’s failed get-rich-quick scheme costs classmates
A student at&nbsp;one of Melbourne's elite private schools has allegedly fleeced up to $185,000 from classmates in a failed&nbsp;get-rich-quick&nbsp;scheme. ...

Resources last updated: 3/23/2016 4:17:17 PM