php-windows Digest 10 Sep 2003 11:23:20 -0000 Issue 1904

Topics (messages 21333 through 21338):

Re: Problem writing to a file
        21333 by: chris.neale.somerfield.co.uk
        21335 by: Luis Moreira
        21336 by: George Pitcher
        21337 by: Gerardo Rojas
        21338 by: Stephen

No answers found - Why var and why & ?
        21334 by: André Cupini

Administrivia:

To subscribe to the digest, e-mail:
        [EMAIL PROTECTED]

To unsubscribe from the digest, e-mail:
        [EMAIL PROTECTED]

To post to the list, e-mail:
        [EMAIL PROTECTED]


----------------------------------------------------------------------
--- Begin Message ---
George,

In the following line you open file $fp...

if (!$fp = fopen($fp2, 'w')) {

but then you try to write to file handle $fp2...

if (!fwrite($fp2, $content)) {

The file name is stored in $fp2 but you've named the handle as $fp. Change
the $fp2 to $fp in the above line that might fix it. Maybe also move the
rename command to after the file close statements, although it might work as
it is.

The Chmod statement will probably work now too....

Hope that helps..

Regards

Chris Neale
Contract Developer
Somerfield Store Ltd.

-----Original Message-----
From: George Pitcher [mailto:[EMAIL PROTECTED]
Sent: 09 September 2003 14:38
To: [EMAIL PROTECTED]
Subject: Problem writing to a file


Hi all,

I'm having a problem writing to a text file.

This is the error message:
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Warning: fwrite():
supplied argument is not a valid stream resource in
C:\Inetpub\wwwroot\packtracker\lse\pub_req_start2.php on line 276
Cannot write to file
(C:\inetpub\wwwroot\packtracker\LSE\IR201_1770.txt)
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

This is the code:
-----------------------------------------------------------------
$fp2 = "C:\\inetpub\\wwwroot\packtracker\\LSE\\".$cr.".txt";
$fp3 = "C:\\inetpub\\wwwroot\packtracker\\LSE\\".$cr.".doc";
$fn1 = file_get_contents("pub_letter.txt");
// replace some of the content placeholders with variables <<<
$content = $fn1;
if (!$fp = fopen($fp2, 'w')) {
    print "Cannot open the bloody file ($fp2)";
    exit;
}
// chmod($fp2,222); tried this - no effect
if (!fwrite($fp2, $content)) {
    print "Cannot write to file ($fp2)";
    exit;
}
rename($fp2,$fp3);
fclose($fp3);
fclose($fp2);
if($contact_route == 'Email' | $contact_route == 'email') {
----------------------------------------------------------------

So as you can see, I load a text file (actually its RTF saved as text),
parse it then write it to an open txt file, then rename that as a Word doc.

I'm running this on NT with PHP 4.3.2. The folder has write access for the
web user.

Any suggestions?

Cheers

George

===

George Pitcher
HERON Technical Manager
Ingenta plc
23-38 Hythe Bridge Street, Oxford, OX1 2ET
T +44 (0)1865 799051 direct
T +44 (0)1865 799000 switchboard
F +44 (0)1865 799134
E [EMAIL PROTECTED]

www.ingenta.com

Ingenta: Empowering the exchange of academic and professional content
online.
 
If you are not the intended recipient of this e-mail, please preserve the
confidentiality of it and advise the sender immediately of any error in
transmission. Any disclosure, copying, distribution or action taken, or
omitted to be taken, by an unauthorised recipient in reliance upon the
contents of this e-mail is prohibited. Somerfield cannot accept liability
for any damage which you may sustain as a result of software viruses so
please carry out your own virus checks before opening an attachment. In
replying to this e-mail you are granting the right for that reply to be
forwarded to any other individual within the business and also to be read by
others. Any views expressed by an individual within this message do not
necessarily reflect the views of Somerfield.  Somerfield reserves the right
to intercept, monitor and record communications for lawful business
purposes.

--- End Message ---
--- Begin Message ---
You have these two lines
$fp2 = "C:\\inetpub\\wwwroot\packtracker\\LSE\\".$cr.".txt";
$fp3 = "C:\\inetpub\\wwwroot\packtracker\\LSE\\".$cr.".doc";

Why do you have double slashes on every place but one ?  :-)

Luis

----- Original Message -----
From: "George Pitcher" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, September 09, 2003 3:37 PM
Subject: [PHP-WIN] Problem writing to a file


> Hi all,
>
> I'm having a problem writing to a text file.
>
> This is the error message:
> = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
> Warning: fwrite():
> supplied argument is not a valid stream resource in
> C:\Inetpub\wwwroot\packtracker\lse\pub_req_start2.php on line 276
> Cannot write to file
> (C:\inetpub\wwwroot\packtracker\LSE\IR201_1770.txt)
> = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
>
> This is the code:
> -----------------------------------------------------------------
> $fp2 = "C:\\inetpub\\wwwroot\packtracker\\LSE\\".$cr.".txt";
> $fp3 = "C:\\inetpub\\wwwroot\packtracker\\LSE\\".$cr.".doc";
> $fn1 = file_get_contents("pub_letter.txt");
> // replace some of the content placeholders with variables <<<
> $content = $fn1;
> if (!$fp = fopen($fp2, 'w')) {
>     print "Cannot open the bloody file ($fp2)";
>     exit;
> }
> // chmod($fp2,222); tried this - no effect
> if (!fwrite($fp2, $content)) {
>     print "Cannot write to file ($fp2)";
>     exit;
> }
> rename($fp2,$fp3);
> fclose($fp3);
> fclose($fp2);
> if($contact_route == 'Email' | $contact_route == 'email') {
> ----------------------------------------------------------------
>
> So as you can see, I load a text file (actually its RTF saved as text),
> parse it then write it to an open txt file, then rename that as a Word
doc.
>
> I'm running this on NT with PHP 4.3.2. The folder has write access for the
> web user.
>
> Any suggestions?
>
> Cheers
>
> George
>
> ===
>
> George Pitcher
> HERON Technical Manager
> Ingenta plc
> 23-38 Hythe Bridge Street, Oxford, OX1 2ET
> T +44 (0)1865 799051 direct
> T +44 (0)1865 799000 switchboard
> F +44 (0)1865 799134
> E [EMAIL PROTECTED]
>
> www.ingenta.com
>
> Ingenta: Empowering the exchange of academic and professional content
> online.
>
> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

--- End Message ---
--- Begin Message ---
Thanks for the pointers guys.

The revised code (it works) is:

$fp2 = "C:\\inetpub\\wwwroot\\packtracker\\LSE\\".$cr.".txt";
if (!$fp2 = fopen($fp2, 'w')) {
    print "Cannot open the bloody file ($fp2)";
    exit;
}
if (!fwrite($fp2, $content)) {
    print "Cannot write to file ($fp2)";
    exit;
}
fclose($fp2);
rename($cr.".txt",$cr.".doc");

It may be of use to someone else.

Cheers

George

> -----Original Message-----
> From: Svensson, B.A.T. (HKG) [mailto:[EMAIL PROTECTED]
> Sent: 9 September 2003 3:54 pm
> To: George Pitcher
> Subject: RE: [PHP-WIN] Problem writing to a file
> 
> 
> Try us the file pointer to write to the file
> instead of the file name, then it should work.
> 
> > -----Original Message-----
> > From: George Pitcher [mailto:[EMAIL PROTECTED]
> > Sent: Tuesday, September 09, 2003 4:38 PM
> > To: [EMAIL PROTECTED]
> > Subject: [PHP-WIN] Problem writing to a file
> > 
> > 
> > Hi all,
> > 
> > I'm having a problem writing to a text file.
> > 
> > This is the error message:
> > = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
> > Warning: fwrite():
> > supplied argument is not a valid stream resource in
> > C:\Inetpub\wwwroot\packtracker\lse\pub_req_start2.php on line 276
> > Cannot write to file
> > (C:\inetpub\wwwroot\packtracker\LSE\IR201_1770.txt)
> > = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
> > 
> > This is the code:
> > -----------------------------------------------------------------
> > $fp2 = "C:\\inetpub\\wwwroot\packtracker\\LSE\\".$cr.".txt";
> > $fp3 = "C:\\inetpub\\wwwroot\packtracker\\LSE\\".$cr.".doc";
> > $fn1 = file_get_contents("pub_letter.txt");
> > // replace some of the content placeholders with variables <<<
> > $content = $fn1;
> > if (!$fp = fopen($fp2, 'w')) {
> >     print "Cannot open the bloody file ($fp2)";
> >     exit;
> > }
> > // chmod($fp2,222); tried this - no effect
> > if (!fwrite($fp2, $content)) {
> >     print "Cannot write to file ($fp2)";
> >     exit;
> > }
> > rename($fp2,$fp3);
> > fclose($fp3);
> > fclose($fp2);
> > if($contact_route == 'Email' | $contact_route == 'email') {
> > ----------------------------------------------------------------
> > 
> > So as you can see, I load a text file (actually its RTF saved as text),
> > parse it then write it to an open txt file, then rename that as 
> a Word doc.
> > 
> > I'm running this on NT with PHP 4.3.2. The folder has write 
> access for the
> > web user.
> > 
> > Any suggestions?
> > 
> > Cheers
> > 
> > George
> > 
> > ===
> > 
> > George Pitcher
> > HERON Technical Manager
> > Ingenta plc
> > 23-38 Hythe Bridge Street, Oxford, OX1 2ET
> > T +44 (0)1865 799051 direct
> > T +44 (0)1865 799000 switchboard
> > F +44 (0)1865 799134
> > E [EMAIL PROTECTED]
> > 
> > www.ingenta.com
> > 
> > Ingenta: Empowering the exchange of academic and professional content
> > online.
> > 
> > -- 
> > PHP Windows Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> > 
> 

--- End Message ---
--- Begin Message ---
You should not have the same variable name for 2 seperate things.  1 variable is the 
filename, 2 variable is the File Descriptor.

$file = "C:\\inetpub\\wwwroot\\packtracker\\LSE\\".$cr.".txt";
$fd   = fopen($file, 'w');

--
Gerardo S. Rojas
mailto:[EMAIL PROTECTED]


-----Original Message-----
From: George Pitcher [mailto:[EMAIL PROTECTED]
Sent: Tuesday, September 09, 2003 11:18 AM
To: [EMAIL PROTECTED]
Subject: RE: [PHP-WIN] Problem writing to a file


Thanks for the pointers guys.

The revised code (it works) is:

$fp2 = "C:\\inetpub\\wwwroot\\packtracker\\LSE\\".$cr.".txt";
if (!$fp2 = fopen($fp2, 'w')) {
    print "Cannot open the bloody file ($fp2)";
    exit;
}
if (!fwrite($fp2, $content)) {
    print "Cannot write to file ($fp2)";
    exit;
}
fclose($fp2);
rename($cr.".txt",$cr.".doc");

It may be of use to someone else.

Cheers

George

> -----Original Message-----
> From: Svensson, B.A.T. (HKG) [mailto:[EMAIL PROTECTED]
> Sent: 9 September 2003 3:54 pm
> To: George Pitcher
> Subject: RE: [PHP-WIN] Problem writing to a file
> 
> 
> Try us the file pointer to write to the file
> instead of the file name, then it should work.
> 
> > -----Original Message-----
> > From: George Pitcher [mailto:[EMAIL PROTECTED]
> > Sent: Tuesday, September 09, 2003 4:38 PM
> > To: [EMAIL PROTECTED]
> > Subject: [PHP-WIN] Problem writing to a file
> > 
> > 
> > Hi all,
> > 
> > I'm having a problem writing to a text file.
> > 
> > This is the error message:
> > = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
> > Warning: fwrite():
> > supplied argument is not a valid stream resource in
> > C:\Inetpub\wwwroot\packtracker\lse\pub_req_start2.php on line 276
> > Cannot write to file
> > (C:\inetpub\wwwroot\packtracker\LSE\IR201_1770.txt)
> > = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
> > 
> > This is the code:
> > -----------------------------------------------------------------
> > $fp2 = "C:\\inetpub\\wwwroot\packtracker\\LSE\\".$cr.".txt";
> > $fp3 = "C:\\inetpub\\wwwroot\packtracker\\LSE\\".$cr.".doc";
> > $fn1 = file_get_contents("pub_letter.txt");
> > // replace some of the content placeholders with variables <<<
> > $content = $fn1;
> > if (!$fp = fopen($fp2, 'w')) {
> >     print "Cannot open the bloody file ($fp2)";
> >     exit;
> > }
> > // chmod($fp2,222); tried this - no effect
> > if (!fwrite($fp2, $content)) {
> >     print "Cannot write to file ($fp2)";
> >     exit;
> > }
> > rename($fp2,$fp3);
> > fclose($fp3);
> > fclose($fp2);
> > if($contact_route == 'Email' | $contact_route == 'email') {
> > ----------------------------------------------------------------
> > 
> > So as you can see, I load a text file (actually its RTF saved as text),
> > parse it then write it to an open txt file, then rename that as 
> a Word doc.
> > 
> > I'm running this on NT with PHP 4.3.2. The folder has write 
> access for the
> > web user.
> > 
> > Any suggestions?
> > 
> > Cheers
> > 
> > George
> > 
> > ===
> > 
> > George Pitcher
> > HERON Technical Manager
> > Ingenta plc
> > 23-38 Hythe Bridge Street, Oxford, OX1 2ET
> > T +44 (0)1865 799051 direct
> > T +44 (0)1865 799000 switchboard
> > F +44 (0)1865 799134
> > E [EMAIL PROTECTED]
> > 
> > www.ingenta.com
> > 
> > Ingenta: Empowering the exchange of academic and professional content
> > online.
> > 
> > -- 
> > PHP Windows Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> > 
> 

-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

--- End Message ---
--- Begin Message ---
Sorry to say it, but that is quite sloppy coding. This highlights why it is
important to give variables meaningful names! In the code below, George has
assigned the location of his file to a pointer, but then over-written it
with the pointer result of fopen.

> $fp2 = "C:\\inetpub\\wwwroot\\packtracker\\LSE\\".$cr.".txt";
> if (!$fp2 = fopen($fp2, 'w')) {
>     print "Cannot open the bloody file ($fp2)";
>     exit;
> }
> if (!fwrite($fp2, $content)) {
>     print "Cannot write to file ($fp2)";
>     exit;
> }
> fclose($fp2);
> rename($cr.".txt",$cr.".doc");

A better solution would be to have two different variables like this:

> $file_location = "C:\\inetpub\\wwwroot\\packtracker\\LSE\\".$cr.".txt";
> if ( !$file_pointer = fopen( $file_location, 'w' ) ) {
>     print "Cannot open the bloody file ( $file_location )";
>     exit;
> }
> if ( !fwrite( $file_pointer, $content ) ) {
>     print "Cannot write to file ( $file_location )";
>     exit;
> }
> fclose( $file_pointer );
> rename($cr.".txt",$cr.".doc");

As you can see, it makes it much more obvious what does what, and so easier
for you/others to come back to in a few months time to make changes to.
Don't be afraid to name your variables properly!

Stephen

--- End Message ---
--- Begin Message ---
Save all programers! (sorry my "brazilian english")

I have a simple doubt, but i´m tired because i not found answers...
Why, inside a class, declarare $this variables in a format "var  $varname;"
before of a constructor?
And, please, what intend the "&" signal before functions name?

I know the arguments reference methods like this:
function bla(&$reference_arg)

But what's the diference of the sintax:
function &bla(&$var)

Thanks for attention

-- 
André Cupini
Programador - NeoBiz
[EMAIL PROTECTED]
http://www.neobiz.com.br

--- End Message ---

Reply via email to