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

Home » Imported messages » comp.lang.php » Command line cannot fwrite, browser can
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
Command line cannot fwrite, browser can [message #174561] Fri, 17 June 2011 21:22 Go to next message
Adrienne Boswell is currently offline  Adrienne Boswell
Messages: 25
Registered: October 2010
Karma: 0
Junior Member
Okay, I give up! I pulled the very last hair out of my head, and now I
am asking for help.

This is a Win2003 SP2 server running Plesk PHP5 on Microsoft-IIS/6.0.
Why am I using PHP on Win? The main application was written in Classic
ASP, hence the Windows server. I need to run a script from the command
line so I can call it with the task manager to run every night.

Using the command line, the script gives a warning, and then fails saying
it cannot write to a file. Using a browser, the script works flawlessly.

I am thinking it might be a permission issue? I checked and IUSER the
DOMAIN USER, SYSTEM and Administrator have full permissions on the file
(s) in question. Is there another user I should be including? The batch
file is running as Administrator.

The other issue is that the file giving a warning IS on the server. All
the other files mentioned are found without a problem - and again this
only happens with the command line.

This is the error I am getting:
C:\Inetpub\vhosts\aloyaltycard.com\httpdocs\groupmail>cd c:\parallels
\plesk\additional\pleskphp5
C:\Parallels\Plesk\Additional\PleskPHP5>php.exe c:\inetpub\vhosts
\aloyaltycard.com\httpdocs\groupmail\groupmail.php

Warning: file_get_contents(groupmail1_noname.txt): failed to open stream:
No such file or directory in C:\Inetpub\vhosts\aloyaltycard.com\httpdocs
\groupmail\groupmail.php on line 88
cannot write to groupmail.html

Here also is the contents of the folder in question:

Volume in drive C has no label.
Volume Serial Number is E454-BB08

Directory of C:\Inetpub\vhosts\aloyaltycard.com\httpdocs\groupmail

06/17/2011 01:15 PM <DIR> .
06/17/2011 01:15 PM <DIR> ..
06/17/2011 12:37 PM 3,102 groupmail.html
06/17/2011 01:13 PM 5,515 groupmail.php
06/10/2011 05:50 PM 485 groupmail1.txt
06/10/2011 05:51 PM 443 groupmail1_noname.txt
06/10/2011 05:50 PM 93 groupmail1_txt.txt
06/10/2011 05:50 PM 1,838 groupmail2.txt
06/10/2011 05:50 PM 1,858 groupmail2_candidates.txt
06/10/2011 05:50 PM 1,082 groupmail2_customers.txt
06/10/2011 05:50 PM 834 groupmail2_nonames.txt
06/10/2011 05:50 PM 1,515 groupmail2_txt.txt
06/17/2011 12:37 PM 3,122 groupmail_candidates.html
06/17/2011 12:37 PM 2,346 groupmail_customers.html
06/17/2011 12:37 PM 2,056 groupmail_nonames.html
06/17/2011 12:36 PM 138 groupmail_prepare.bat

Just for shits and giggles, here's the contents of my batch file as well:
@echo on
cd c:\parallels\plesk\additional\pleskphp5
php.exe c:\inetpub\vhosts\aloyaltycard.com\httpdocs\groupmail
\groupmail.php


Here is the relavent PHP:

$filename = "groupmail.html";
$file_candidate = "groupmail_candidates.html";
$file_customers = "groupmail_customers.html";
$file_nonames = "groupmail_nonames.html";
$groupmhtml1 = "groupmail1.txt";
$groupmhtml1noname = "groupmail1_noname.txt";

//this above file is the one it cannot find

$groupmhtml2 = "groupmail2.txt";
$groupmcandidate = "groupmail2_candidates.txt";
$groupmcustomers = "groupmail2_customers.txt";
$groupmnonames = "groupmail2_nonames.txt";


$groupmail = fopen( $filename,'w' ) or die( 'cannot open
groupmail.html' );
$candidates = fopen( $file_candidate,'w' ) or die ( 'cannot open
groupmail_candidates.html' );
$customers = fopen( $file_customers,'w' ) or die( 'cannot open'.
$file_customers );
$nonames = fopen( $file_nonames,'w' ) or die( 'cannot open'.
$file_nonames );
$group1 = fopen( $groupmhtml1,'r' ) or die( 'cannot open
groupmail1.txt' );
$group2 = fopen( $groupmhtml2,'r' ) or die( 'cannot open
groupmail2.txt' );
$firstpart = file_get_contents($groupmhtml1);
$firstnoname = file_get_contents( $groupmhtml1noname );

//warning comes right here

fwrite( $groupmail,$firstpart ) or die( 'cannot write to
groupmail.html' );

//failure occurs right here


fwrite( $candidates,$firstpart ) or die ( 'cannot write to
groupmail_candidates.html' );
fwrite( $customers,$firstpart ) or die( 'cannot write to'.
$file_customers );
fwrite( $nonames,$firstnoname ) or die( 'cannot write to'.
$file_nonames );

$sql = "SELECT merchant, address1, line2, phone, email, uri,
primarycategory, pricategory_id, merchant_ipk, coupon_id, printsleft,
validto, amount, dollarpercent, image_path FROM madecoupons WHERE status
<> 'D' ORDER BY id DESC LIMIT 2";
$rs = db_query( $sql );

$insert = "INSERT INTO madecoupons_mailed (merchant_id, email)
VALUES ";


while ($row = mysql_fetch_array($rs,MYSQL_NUM))
{

$merchant = str_replace( "~","'",$row[ 0 ] );
$address1 = $row[ 1];
$line2 = $row[ 2];
$phone = $row[ 3];
$email = $row[ 4];
$uri = $row[ 5];
$category = $row[ 6];
$catid = $row[ 7];
$merchant_id = $row[ 8];
$coupon_id = $row[ 9];
$maxprints = $row[ 10];
$description = "Get 10% off!";
$exceptions = "";
$validto = $row[ 11];
$amount = $row[ 12];
$dollarpercent = $row[ 13];
$image_path = $row[ 14 ];

$linetowrite = "<div style=" . chr( 34) . "float: left; font-
size: 70%; margin: 0 1em .5em 0; width: 200px; background-color:#fff;
padding:0 .5em 0 .5em; border:1px solid #c0c0c0; text-align:center;" .
chr( 34) . "><h2><a href=" . chr( 34 ) .
"http://aloyaltycard.com/coupon.asp?sid=" . $coupon_id . chr( 34 ) .
">" . $merchant . "</a></h2>" .$image_path . "<br />".$description ."<br
/>".$exceptions . "<br /></div>";
//echo $linetowrite;
fwrite( $groupmail,$linetowrite );
fwrite ( $candidates,$linetowrite );
fwrite ( $customers,$linetowrite );
fwrite( $nonames,$linetowrite );

$insert = $insert . "( ".$merchant_id.",'".mysql_real_escape_string
($email)."' ),";

}
mysql_free_result($rs);
$lastpart = file_get_contents( $groupmhtml2 );
$lastcandidate = file_get_contents( $groupmcandidate );
$lastcustomers = file_get_contents( $groupmcustomers );
$lastnonames = file_get_contents( $groupmnonames );
fwrite( $groupmail,$lastpart );
fwrite( $candidates,$lastcandidate );
fwrite( $customers,$lastcustomers );
fwrite( $nonames,$lastnonames );

$insert = substr( $insert,0,strlen( $insert )-1 );

db_query( $insert );

mysql_close( );


--
Adrienne Boswell at Home
Arbpen Web Site Design Services
http://www.cavalcade-of-coding.info
Please respond to the group so others can share
Re: Command line cannot fwrite, browser can [message #174564 is a reply to message #174561] Sat, 18 June 2011 00:16 Go to previous messageGo to next message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma: 0
Senior Member
On Fri, 17 Jun 2011 21:22:52 +0000, Adrienne Boswell wrote:

> I am thinking it might be a permission issue? I checked and IUSER the
> DOMAIN USER, SYSTEM and Administrator have full permissions on the file
> (s) in question. Is there another user I should be including? The
> batch file is running as Administrator.

Permissions on the directory maybe?

Rgds

Denis McMahon
Re: Command line cannot fwrite, browser can [message #174566 is a reply to message #174561] Sat, 18 June 2011 00:35 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 6/17/2011 5:22 PM, Adrienne Boswell wrote:
> Okay, I give up! I pulled the very last hair out of my head, and now I
> am asking for help.
>
> This is a Win2003 SP2 server running Plesk PHP5 on Microsoft-IIS/6.0.
> Why am I using PHP on Win? The main application was written in Classic
> ASP, hence the Windows server. I need to run a script from the command
> line so I can call it with the task manager to run every night.
>
> Using the command line, the script gives a warning, and then fails saying
> it cannot write to a file. Using a browser, the script works flawlessly.
>
> I am thinking it might be a permission issue? I checked and IUSER the
> DOMAIN USER, SYSTEM and Administrator have full permissions on the file
> (s) in question. Is there another user I should be including? The batch
> file is running as Administrator.
>
> The other issue is that the file giving a warning IS on the server. All
> the other files mentioned are found without a problem - and again this
> only happens with the command line.
>
> This is the error I am getting:
> C:\Inetpub\vhosts\aloyaltycard.com\httpdocs\groupmail>cd c:\parallels
> \plesk\additional\pleskphp5
> C:\Parallels\Plesk\Additional\PleskPHP5>php.exe c:\inetpub\vhosts
> \aloyaltycard.com\httpdocs\groupmail\groupmail.php
>
> Warning: file_get_contents(groupmail1_noname.txt): failed to open stream:
> No such file or directory in C:\Inetpub\vhosts\aloyaltycard.com\httpdocs
> \groupmail\groupmail.php on line 88
> cannot write to groupmail.html
>

<lots of other stuff snipped>

Classic windows permission issue. First of all, ensure you're writing
to the file you think you are (i.e. use absolute paths, etc.). Then try
a windows-related newsgroup.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: Command line cannot fwrite, browser can [message #174568 is a reply to message #174566] Sat, 18 June 2011 03:05 Go to previous messageGo to next message
Adrienne Boswell is currently offline  Adrienne Boswell
Messages: 25
Registered: October 2010
Karma: 0
Junior Member
Gazing into my crystal ball I observed Jerry Stuckle
<jstucklex(at)attglobal(dot)net> writing in news:itgrt2$u7d$1(at)dont-email(dot)me:

> On 6/17/2011 5:22 PM, Adrienne Boswell wrote:
>> Okay, I give up! I pulled the very last hair out of my head, and now
>> I am asking for help.
>>
>> This is a Win2003 SP2 server running Plesk PHP5 on Microsoft-IIS/6.0.
>> Why am I using PHP on Win? The main application was written in
>> Classic ASP, hence the Windows server. I need to run a script from
>> the command line so I can call it with the task manager to run every
>> night.
>>
>> Using the command line, the script gives a warning, and then fails
>> saying it cannot write to a file. Using a browser, the script works
>> flawlessly.
>>
>> I am thinking it might be a permission issue? I checked and IUSER the
>> DOMAIN USER, SYSTEM and Administrator have full permissions on the
>> file (s) in question. Is there another user I should be including?
>> The batch file is running as Administrator.
>>
<snip>

>
> <lots of other stuff snipped>
>
> Classic windows permission issue. First of all, ensure you're writing
> to the file you think you are (i.e. use absolute paths, etc.). Then
> try a windows-related newsgroup.
>

Thanks, Jerry. I was pretty sure it was a permission issue. I'll head
over to a windows group, and hopefully they won't tell me it's an .net
issue like they usually do. By the way, if you're a father, Happy
Father's Day, heck, have a happy one even you're not.

--
Adrienne Boswell at Home
Arbpen Web Site Design Services
http://www.cavalcade-of-coding.info
Please respond to the group so others can share
Re: Command line cannot fwrite, browser can [message #174570 is a reply to message #174561] Sat, 18 June 2011 06:20 Go to previous messageGo to next message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma: 0
Senior Member
Adrienne Boswell wrote:

> Okay, I give up! I pulled the very last hair out of my head, and now I
> am asking for help.

Your posting style just begs for <http://www.catb.org/~esr/faqs/smart-
questions.html> as the only answer (in particular
<http://www.catb.org/~esr/faqs/smart-questions.html#beprecise>).

But I think I have actually found some relevant facts between the lines of
the 179-lines diary entry that you have posted in place of your good
question.

Anyhow, please read that tutorial to make it better next time.

> […]
> This is the error I am getting:
> C:\Inetpub\vhosts\aloyaltycard.com\httpdocs\groupmail>cd c:\parallels
> \plesk\additional\pleskphp5
> C:\Parallels\Plesk\Additional\PleskPHP5>php.exe c:\inetpub\vhosts
> \aloyaltycard.com\httpdocs\groupmail\groupmail.php
>
> Warning: file_get_contents(groupmail1_noname.txt): failed to open stream:
> No such file or directory in C:\Inetpub\vhosts\aloyaltycard.com\httpdocs
> \groupmail\groupmail.php on line 88
> cannot write to groupmail.html
>
> […]
> Directory of C:\Inetpub\vhosts\aloyaltycard.com\httpdocs\groupmail
> […]
> 06/17/2011 12:37 PM 3,102 groupmail.html
> 06/17/2011 01:13 PM 5,515 groupmail.php
> [...]
> 06/10/2011 05:51 PM 443 groupmail1_noname.txt
> […]
>
> Just for shits and giggles, here's the contents of my batch file as well:
> @echo on
> cd c:\parallels\plesk\additional\pleskphp5
> php.exe c:\inetpub\vhosts\aloyaltycard.com\httpdocs\groupmail
> \groupmail.php
>
> Here is the relavent PHP:

No, about 99% of it is quite irrelevant to your question. Does "reduce test
case" ring a bell?

> $filename = "groupmail.html";
> […]
> $groupmhtml1noname = "groupmail1_noname.txt";
>
> //this above file is the one it cannot find

(You don't say …)

> […]
> $groupmail = fopen( $filename,'w' ) or die( 'cannot open
> groupmail.html' );

<http://www.phpfreaks.com/blog/or-die-must-die>

> […]
> $firstpart = file_get_contents($groupmhtml1);
> $firstnoname = file_get_contents( $groupmhtml1noname );
>
> //warning comes right here

(You don't say …)

> fwrite( $groupmail,$firstpart ) or die( 'cannot write to
> groupmail.html' );
>
> //failure occurs right here

(You don't say …)

So let me get this straight:

1. You are explicitly cd-ing to c:\parallels\plesk\additional\pleskphp5
(for whatever reason)

2. You run php.exe
c:\inetpub\vhosts\aloyaltycard.com\httpdocs\groupmail\groupmail.php

3. You *wonder* why php.exe cannot find the files in the *current*
*working* *directory* (c:\parallels\plesk\additional\pleskphp5)
or can write to it?

$ cat ~/tmp/files.php
<?php echo realpath('.') . "\n";

$ php ~/tmp/files.php
/

(This is on GNU/Linux but that does not make a difference, of course.)

ISTM you should have more cups of tea[tm] before coding. Besides, you
cannot just take any PHP Web script and run it with the PHP CLI; to begin
with, the Web script runs under $_SERVER['DOCUMENT_ROOT'] in a much more
restricted environment; the CLI runs under the root of the local filesystem
(or "drive", in Windoze).


HTH

PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
Re: Command line cannot fwrite, browser can [message #174572 is a reply to message #174570] Sat, 18 June 2011 08:05 Go to previous messageGo to next message
Adrienne Boswell is currently offline  Adrienne Boswell
Messages: 25
Registered: October 2010
Karma: 0
Junior Member
Gazing into my crystal ball I observed Thomas 'PointedEars' Lahn
<PointedEars(at)web(dot)de> writing in news:8844491(dot)SEqChMirdb(at)PointedEars(dot)de:

>> $filename = "groupmail.html";
>> $groupmhtml1noname = "groupmail1_noname.txt";
>>
>> //this above file is the one it cannot find
>
> (You don't say)

Turns out I needed to use a single quote instead of a double quote. The
script is running just fine now.

>
>>
>> $groupmail = fopen( $filename,'w' ) or die( 'cannot open
>> groupmail.html' );
>
> <http://www.phpfreaks.com/blog/or-die-must-die>
>


Thank you for all your help, and the link. I have read it and will
implement it.

--
Adrienne Boswell at Home
Arbpen Web Site Design Services
http://www.cavalcade-of-coding.info
Please respond to the group so others can share
Re: Command line cannot fwrite, browser can [message #174573 is a reply to message #174572] Sat, 18 June 2011 08:27 Go to previous messageGo to next message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma: 0
Senior Member
Adrienne Boswell wrote:

> Thomas 'PointedEars' Lahn [wrote]:
>>> $filename = "groupmail.html";
>>> $groupmhtml1noname = "groupmail1_noname.txt";
>>>
>>> //this above file is the one it cannot find
>>
>> (You don't say)
>
> Turns out I needed to use a single quote instead of a double quote. The
> script is running just fine now.

Now I am curious: Where exactly?

>>> $groupmail = fopen( $filename,'w' ) or die( 'cannot open
>>> groupmail.html' );
>>
>> <http://www.phpfreaks.com/blog/or-die-must-die>
>
> Thank you for all your help, and the link. I have read it and will
> implement it.

You're welcome.


PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
Re: Command line cannot fwrite, browser can [message #174574 is a reply to message #174561] Sat, 18 June 2011 11:10 Go to previous messageGo to next message
Bernd Schulz is currently offline  Bernd Schulz
Messages: 10
Registered: September 2010
Karma: 0
Junior Member
Am 17.06.2011 23:22, schrieb Adrienne Boswell:
>
> Warning: file_get_contents(groupmail1_noname.txt): failed to open stream:
> No such file or directory in C:\Inetpub\vhosts\aloyaltycard.com\httpdocs
> \groupmail\groupmail.php on line 88
> cannot write to groupmail.html
>
You are in the wrong directory, when your Script starts.
You are looking for:
http://php.net/manual/de/function.chdir.php
Re: Command line cannot fwrite, browser can [message #174576 is a reply to message #174572] Sat, 18 June 2011 12:19 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 6/18/2011 4:05 AM, Adrienne Boswell wrote:
> Gazing into my crystal ball I observed Thomas 'PointedEars' Lahn
> <PointedEars(at)web(dot)de> writing in news:8844491(dot)SEqChMirdb(at)PointedEars(dot)de:
>
>>> $filename = "groupmail.html";
>>> $groupmhtml1noname = "groupmail1_noname.txt";
>>>
>>> //this above file is the one it cannot find
>>
>> (You don't say)
>
> Turns out I needed to use a single quote instead of a double quote. The
> script is running just fine now.
>
>>
>>>
>>> $groupmail = fopen( $filename,'w' ) or die( 'cannot open
>>> groupmail.html' );
>>
>> <http://www.phpfreaks.com/blog/or-die-must-die>
>>
>
>
> Thank you for all your help, and the link. I have read it and will
> implement it.
>

I think you have another problem. Single vs. double quotes would not
make any difference in the code you posted.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: Command line cannot fwrite, browser can [message #174578 is a reply to message #174576] Sat, 18 June 2011 16:08 Go to previous messageGo to next message
Adrienne Boswell is currently offline  Adrienne Boswell
Messages: 25
Registered: October 2010
Karma: 0
Junior Member
Gazing into my crystal ball I observed Jerry Stuckle
<jstucklex(at)attglobal(dot)net> writing in news:iti559$vvt$1(at)dont-email(dot)me:

> On 6/18/2011 4:05 AM, Adrienne Boswell wrote:
>> Gazing into my crystal ball I observed Thomas 'PointedEars' Lahn
>> <PointedEars(at)web(dot)de> writing in
news:8844491(dot)SEqChMirdb(at)PointedEars(dot)de:
>>
>>>> $filename = "groupmail.html";
>>>> $groupmhtml1noname = "groupmail1_noname.txt";
>>>>
>>>> //this above file is the one it cannot find
>>>
>>> (You don't say)
>>
>> Turns out I needed to use a single quote instead of a double quote.
The
>> script is running just fine now.
>>
>>>
>>>>
>>>> $groupmail = fopen( $filename,'w' ) or die( 'cannot open
>>>> groupmail.html' );
>>>
>>> <http://www.phpfreaks.com/blog/or-die-must-die>
>>>
>>
>>
>> Thank you for all your help, and the link. I have read it and will
>> implement it.
>>
>
> I think you have another problem. Single vs. double quotes would not
> make any difference in the code you posted.
>

Originally, I was not using an absolute path, just the name of the file,
and the script was saying the last file was not found, and could not
write to the first file.

Then, I tried using the whole path, and I got a message about an invalid
stream, and I Googled and found a post about single quotes vs double
quotes, tried it, and it worked.

Yes, this is nagging me, too. I just checked it ran it right now (I also
moved the script so it is not accessible to the WWW), and it's doing just
fine. So far so good. I'm letting sleeping dogs lie, for now.

--
Adrienne Boswell at Home
Arbpen Web Site Design Services
http://www.cavalcade-of-coding.info
Please respond to the group so others can share
Re: Command line cannot fwrite, browser can [message #174611 is a reply to message #174578] Wed, 22 June 2011 09:48 Go to previous messageGo to next message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma: 0
Senior Member
Adrienne Boswell wrote:

> Jerry Stuckle writing:
>> On 6/18/2011 4:05 AM, Adrienne Boswell wrote:
>>> Thomas 'PointedEars' Lahn writing:
>>>> > $groupmail = fopen( $filename,'w' ) or die( 'cannot open
>>>> > groupmail.html' );
>>>>
>>>> <http://www.phpfreaks.com/blog/or-die-must-die>
>>>
>>> Thank you for all your help, and the link. I have read it and will
>>> implement it.
>>
>> I think you have another problem. Single vs. double quotes would not
>> make any difference in the code you posted.
>
> Originally, I was not using an absolute path, just the name of the file,
> and the script was saying the last file was not found, and could not
> write to the first file.
>
> Then, I tried using the whole path, and I got a message about an invalid
> stream, and I Googled and found a post about single quotes vs double
> quotes, tried it, and it worked.

Jerry is correct: Single quotes vs. double quotes make absolutely no
difference in the code that you have posted, since there are no variable
references in or adjacent to the string values. Without loss of generality,
they also make no difference when enclosing file paths, unless the paths
contain the delimiter character (in which case the string value would end
prematurely, which might contribute to the fact that a file could not be
found).

> Yes, this is nagging me, too. I just checked it ran it right now (I also
> moved the script so it is not accessible to the WWW),

This is not the World Wide Web, an application of the Internet, but Usenet,
a part of the Network News network (a growing part of which is part of the
Internet). So you may – SHOULD – as well post the *relevant* *parts* of
your working code here.

> and it's doing just fine. So far so good. I'm letting sleeping dogs lie,
> for now.

So, without evidence to the contrary, one must assume that you have not
understood what you are doing in the first place, that you are not willing
to understand the problems that this has caused you in the foreseeable
future, and that you are not willing to feed back the insights you have
gained from other code to the community that tried to help you for free.

That puts into serious doubt whether you are worth getting further, rather
time-consuming, answers like the ones I give to you. Think about that.

And skip the attribution novels, please.


PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f806at$ail$1$8300dec7(at)news(dot)demon(dot)co(dot)uk>
Re: Command line cannot fwrite, browser can [message #174629 is a reply to message #174611] Thu, 23 June 2011 03:44 Go to previous messageGo to next message
Adrienne Boswell is currently offline  Adrienne Boswell
Messages: 25
Registered: October 2010
Karma: 0
Junior Member
Thomas 'PointedEars' Lahn <PointedEars(at)web(dot)de> wrote at
news:8855064(dot)SEqChMirdb(at)PointedEars(dot)de:

> Adrienne Boswell wrote:
>
>> Jerry Stuckle writing:
>>> On 6/18/2011 4:05 AM, Adrienne Boswell wrote:
>>>> Thomas 'PointedEars' Lahn writing:
>>>> >> $groupmail = fopen( $filename,'w' ) or die( 'cannot open
>>>> >> groupmail.html' );
>>>> >
>>>> > <http://www.phpfreaks.com/blog/or-die-must-die>
>>>>
>>>> Thank you for all your help, and the link. I have read it and will
>>>> implement it.
>>>
>>> I think you have another problem. Single vs. double quotes would
>>> not make any difference in the code you posted.
>>
>> Originally, I was not using an absolute path, just the name of the
>> file, and the script was saying the last file was not found, and
>> could not write to the first file.
>>
>> Then, I tried using the whole path, and I got a message about an
>> invalid stream, and I Googled and found a post about single quotes vs
>> double quotes, tried it, and it worked.
>
> Jerry is correct: Single quotes vs. double quotes make absolutely no
> difference in the code that you have posted, since there are no
> variable references in or adjacent to the string values. Without loss
> of generality, they also make no difference when enclosing file paths,
> unless the paths contain the delimiter character (in which case the
> string value would end prematurely, which might contribute to the fact
> that a file could not be found).
>
>> Yes, this is nagging me, too. I just checked it ran it right now (I
>> also moved the script so it is not accessible to the WWW),
>
> This is not the World Wide Web, an application of the Internet, but
> Usenet, a part of the Network News network (a growing part of which is
> part of the Internet). So you may – SHOULD – as well post the
> *relevant* *parts* of your working code here.


Ok, here is the relavent piece of code (the relavent parts were snipped by
Jerry).

Originally (with line numbers and I have replaced the real domain with
example.com):

68 $filename = "C:\Inetpub\vhosts\example.com\httpdocs\groupmail
\groupmail.html";

80 $groupmail = fopen( $filename,'w' ) or die( 'cannot open
groupmail.html' );


Warning: fopen(C:\Inetpub?hosts\example.com\httpdocs\groupmail\groupmail.ht
ml): failed to open stream: Invalid argument in C:\Inetpub\vhosts
\example.com\httpdocs\groupmail.php on line 80
cannot open groupmail.html


So when I changed line 68 to:

68 $filename = 'C:\Inetpub\vhosts\example.com\httpdocs\groupmail
\groupmail.html';


>
>> and it's doing just fine. So far so good. I'm letting sleeping dogs
>> lie, for now.
>
> So, without evidence to the contrary, one must assume that you have
> not understood what you are doing in the first place,

Actually, I do understand what I did, and wrote the script to perform what
I expected it to do. On my developer box, Windows 7 Ultimate IIS 6, the
original script ran flawlessly. It was not until I put it on the virtual
host box that it started acting badly.

that you are not
> willing to understand the problems that this has caused you in the
> foreseeable future,

That's why I'm here - to gain insight into what could bite me in the ass in
the future.

and that you are not willing to feed back the
> insights you have gained from other code to the community that tried
> to help you for free.

I beg to differ with you there. I may not contribute much to this
particular group, I am mostly a lurker here, but I do contribute often to
the HTML groups, and when they were alive the ASP classic groups.

>
> That puts into serious doubt whether you are worth getting further,
> rather time-consuming, answers like the ones I give to you. Think
> about that.

One of the reasons I came here was because I have high respect for your
knowledge. You might think that because I'm girl I have thin skin, but I
don't. I have been around Usenet since 1996, so I have seen a lot,
including your latest run-in with Jukka Korpela.


>
> And skip the attribution novels, please.
>
>
> PointedEars



--
Adrienne Boswell at Home
Arbpen Web Site Design Services
http://www.cavalcade-of-coding.info
Please respond to the group so others can share
Re: Command line cannot fwrite, browser can [message #174631 is a reply to message #174629] Thu, 23 June 2011 07:55 Go to previous messageGo to next message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma: 0
Senior Member
Adrienne Boswell wrote:

> Thomas 'PointedEars' Lahn wrote:
>> Adrienne Boswell wrote:
>>> Jerry Stuckle writing:
>>>> Adrienne Boswell wrote:
>>>> > Thomas 'PointedEars' Lahn writing:
>>>> >>> $groupmail = fopen( $filename,'w' ) or die( 'cannot open
>>>> >>> groupmail.html' );
>>>> >> <http://www.phpfreaks.com/blog/or-die-must-die>
>>>> > Thank you for all your help, and the link. I have read it and will
>>>> > implement it.
>>>> I think you have another problem. Single vs. double quotes would
>>>> not make any difference in the code you posted.
>>> […]
>>> Yes, this is nagging me, too. I just checked it ran it right now (I
>>> also moved the script so it is not accessible to the WWW),
>>
>> This is not the World Wide Web, an application of the Internet, but
>> Usenet, a part of the Network News network (a growing part of which is
>> part of the Internet). So you may – SHOULD – as well post the
>> *relevant* *parts* of your working code here.
>
> Ok, here is the relavent piece of code (the relavent parts were snipped by
> Jerry).

ACK, thanks.

> Originally (with line numbers and I have replaced the real domain with
> example.com):
>
> 68 $filename = "C:\Inetpub\vhosts\example.com\httpdocs\groupmail
> \groupmail.html";
>
> 80 $groupmail = fopen( $filename,'w' ) or die( 'cannot open
> groupmail.html' );
>
>
> Warning:
> fopen(C:\Inetpub?hosts\example.com\httpdocs\groupmail\groupmail.ht ml):
> failed to open stream: Invalid argument in C:\Inetpub\vhosts
> \example.com\httpdocs\groupmail.php on line 80 cannot open groupmail.html
>
>
> So when I changed line 68 to:
>
> 68 $filename = 'C:\Inetpub\vhosts\example.com\httpdocs\groupmail
> \groupmail.html';

I can see the problem now. You have used the sequence "\v" in your string
literal. That makes the difference, because in double-quoted strings it is
parsed as a <VT> (vertical tab) character (that originates from early TTYs
and is hardly used nowadays, but kept for backwards compatibility [1]).

Hence the question mark in the warning after the "b" of "Inetpub", and the
missing "v" after it. <VT> is not one of the printable characters, so a
replacement character is used to display it.

In a single-quoted string, that and most other escape sequences carry no
special meaning [2]. So the path fits, and the file can be opened, then.

Since you cannot know beforehand which escape sequences are considered by a
certain version of PHP (other than `\\'), you should always escape literal
backslashes in string literals: "\\" or '\\' [2]. In fact, you MUST escape
them when at the end of the string value, because otherwise \" or \'
constitute escape sequences of themself, and the string value is not
terminated:

$ php -a
Interactive mode enabled

<?php echo "foo\";
^D
PHP Parse error: syntax error, unexpected $end, expecting T_VARIABLE or
T_DOLLAR_OPEN_CURLY_BRACES or T_CURLY_OPEN in - on line 2

$ php -a
Interactive mode enabled

<?php echo 'foo\';
^D
PHP Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE in - on
line 1

$ php -v
PHP 5.3.3-7+squeeze1 with Suhosin-Patch (cli) (built: Mar 18 2011 17:22:52)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
with XCache v1.3.1, Copyright (c) 2005-2010, by mOo
with Xdebug v2.1.0, Copyright (c) 2002-2010, by Derick Rethans
with Suhosin v0.9.32.1, Copyright (c) 2007-2010, by SektionEins GmbH

[FYI: ^D stands for the keyboard shortcut Ctrl+D, which prints <ETX> (end of
text), an ASCII character (code point 0x03) that signals to the process that
the standard input stream is finished. It can also be used to `logout'
quickly from a unixoid shell.]

But for file paths you can replace the backslashes with forward slashes
(`/') even in WinDOS, which do not need to be escaped [3].

>> That puts into serious doubt whether you are worth getting further,
>> rather time-consuming, answers like the ones I give to you. Think
>> about that.
>
> One of the reasons I came here was because I have high respect for your
> knowledge.

Thank you.

> You might think that because I'm girl I have thin skin, but I don't.

All people are the same before PointedEars ;-)

> I have been around Usenet since 1996, so I have seen a lot,
> including your latest run-in with Jukka Korpela.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
What is that supposed to mean? (You may reply to this by PM.)


Please trim your quotes to the relevant minimum [4].


PointedEars
___________
[1] <http://en.wikipedia.org/wiki/Vertical_tab#Tab_characters>
[2] <http://php.net/manual/en/language.types.string.php>
[3] <http://php.net/fopen>
[4] <http://www.netmeister.org/news/learn2quote.html>
--
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(at)news(dot)demon(dot)co(dot)uk> (2004)
Re: Command line cannot fwrite, browser can [message #174637 is a reply to message #174631] Thu, 23 June 2011 15:29 Go to previous messageGo to next message
Adrienne Boswell is currently offline  Adrienne Boswell
Messages: 25
Registered: October 2010
Karma: 0
Junior Member
Thomas 'PointedEars' Lahn
<PointedEars(at)web(dot)de> wrote in news:2972164(dot)SPkdTlGXAF(at)PointedEars(dot)de:

>> 68 $filename = 'C:\Inetpub\vhosts\example.com\httpdocs\groupmail
>> \groupmail.html';
>
> I can see the problem now. You have used the sequence "\v" in your
> string literal. That makes the difference, because in double-quoted
> strings it is parsed as a <VT> (vertical tab) character (that
> originates from early TTYs and is hardly used nowadays, but kept for
> backwards compatibility [1]).
>

Thomas, thank you for pointing out what was going on here, the reasons
and solutions. I understand - oddly enough it reminds me of when the
New York office got my EBCIDIC instructions wrong, and turned one of the
Teletype terminals into a printer (1986) - the terminal understood VT
very well, but it had issues trying to print checks, as the cashiering
department was frantically wondering where the checks were.

I do so much appreciate the time you have taken.



--
Adrienne Boswell at Home
Arbpen Web Site Design Services
http://www.cavalcade-of-coding.info
Please respond to the group so others can share
Re: Command line cannot fwrite, browser can [message #174652 is a reply to message #174637] Thu, 23 June 2011 23:00 Go to previous message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma: 0
Senior Member
Adrienne Boswell wrote:

> Thomas, thank you for pointing out what was going on here, the reasons
> and solutions. I understand - oddly enough it reminds me of when the
> New York office got my EBCIDIC instructions wrong, and turned one of the
> Teletype terminals into a printer (1986) - the terminal understood VT
> very well, but it had issues trying to print checks, as the cashiering
> department was frantically wondering where the checks were.
>
> I do so much appreciate the time you have taken.

You're welcome. And thanks for the funny bedtime story *g*


Regards,

PointedEars
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: pagination driving me insane
Next Topic: insert query error
Goto Forum:
  

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

Current Time: Tue Nov 26 03:37:55 GMT 2024

Total time taken to generate the page: 0.03067 seconds