p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

beginning_php thread: fopen and fwrite issues...


Message #1 by "Bernard Chiu" <admiral_chiu@h...> on Sun, 9 Feb 2003 23:45:26
Hello,

I encountered the following issue and hopefully somebody can help me 
figure out what is going on...

<?php
$query = "select * from user_info order by last_name";
$result = mysql_query($query);
if (($uiresult = mysql_fetch_array($result)) != NULL) {
echo "hi there!";
$somecontent = "Hi there!";
$filename = 'http://xxx:xxx@w.../xml/test.txt';
$handle = fopen($filename, 'a');
fwrite($handle, $somecontent);
fclose($handle);
?>

Everything works fine, except for some reason it doesn't write to the 
file... It was able to detect the presence of the file, and previous 
version of the code confirmed that by showing me a message.

But when I go to check the file after the execution, it is still "0" byte. 

1. What is wrong?
2. Is it possible that some kind of a setting would have to be set on the 
server in order to write things?

Thanks.
Message #2 by esanchez@g... on Tue, 11 Feb 2003 04:07:00
> Hello,

> I encountered the following issue and hopefully somebody can help me 
f> igure out what is going on...

> <?php
$> query = "select * from user_info order by last_name";
$> result = mysql_query($query);
i> f (($uiresult = mysql_fetch_array($result)) != NULL) {
e> cho "hi there!";
$> somecontent = "Hi there!";
$> filename = 'http://xxx:xxx@w.../xml/test.txt';
$> handle = fopen($filename, 'a');
f> write($handle, $somecontent);
f> close($handle);
?> >

> Everything works fine, except for some reason it doesn't write to the 
f> ile... It was able to detect the presence of the file, and previous 
v> ersion of the code confirmed that by showing me a message.

> But when I go to check the file after the execution, it is still "0" byte. 

> 1. What is wrong?
2> . Is it possible that some kind of a setting would have to be set on the 
s> erver in order to write things?

> Thanks.
Message #3 by esanchez@g... on Tue, 11 Feb 2003 04:09:13
Hi!!
Your code seems to be OK, the only thing I see strange could be the line:
 filename = 'http://xxx:xxx@w.../xml/test.txt';
I don't know it this is valid on a php script...
anyway check it out or your query isn't giving the results you might expect...
I wrote the following similar code to yours:

<? 
  $filename='test.txt';
  $handle=fopen($filename, 'a');
  fwrite($handle,"HOLA HOLA!!!");
  fclose($handle);
  print("File writed!!");
?>

and it worked ok...
hope this helps..
regards,
   -eduardo s.m.
Message #4 by "Nikolai Devereaux" <yomama@u...> on Tue, 11 Feb 2003 11:11:31 -0800
> I encountered the following issue and hopefully somebody can help me
> figure out what is going on...
>
> <?php
> $query = "select * from user_info order by last_name";
> $result = mysql_query($query);
> if (($uiresult = mysql_fetch_array($result)) != NULL) {
> echo "hi there!";
> $somecontent = "Hi there!";
> $filename = 'http://xxx:xxx@w.../xml/test.txt';
> $handle = fopen($filename, 'a');
> fwrite($handle, $somecontent);
> fclose($handle);
> ?>
>
> Everything works fine, except for some reason it doesn't write to the
> file... It was able to detect the presence of the file, and previous
> version of the code confirmed that by showing me a message.
>
> But when I go to check the file after the execution, it is still "0" byte.
>
> 1. What is wrong?
> 2. Is it possible that some kind of a setting would have to be set on the
> server in order to write things?


Uh... you're trying to write to a web page?  Can't do it with fwrite().  You
have other options; I would suggest FTPing the file over to the server.


Take care,

Nik


  Return to Index