RE: [PHP-WIN] Problem writing to a file
| From: | Gerardo Rojas | Date: | Tue, 09 Sep 2003 16:51:16 +0000 |
| Subject: | RE: [PHP-WIN] Problem writing to a file | ||
| Groups: | php.windows | ||
| Request: | Send a blank email to php-windows+get-21337@lists.php.net to get a copy of this 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:grojas@strategicinc.com
-----Original Message-----
From: George Pitcher [mailto:george.pitcher@ingenta.com]
Sent: Tuesday, September 09, 2003 11:18 AM
To: php-windows@lists.php.net
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:B.A.T.Svensson@lumc.nl]
> 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:george.pitcher@ingenta.com]
> > Sent: Tuesday, September 09, 2003 4:38 PM
> > To: php-windows@lists.php.net
> > 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 george.pitcher@ingenta.com
> >
> > 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