[PHP-WIN] RE: Problem writing to a file

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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:george.pitcher@ingenta.com]
Sent: 09 September 2003 14:38
To: php-windows@lists.php.net
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 george.pitcher@ingenta.com

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.

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


[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Database Programming]     [PHP Install]     [Kernel Newbies]     [Yosemite Forum]     [PHP Books]

  Powered by Linux