Jump to content

[SOLVED] fwrite() doesn't work - why?


Gregadeath

Recommended Posts

I'm having a spot of trouble using the fwrite() function.

 

- the preceding fopen() call does generate a new file as expected, and, if it already exists, overwrites the file.

- permissions on the folder I'm using are set to 777

- on the fwrite() and fclose() lines, this error message is generated: Warning: fwrite(): supplied argument is not a valid stream resource in...

 

 

Here's the code:

 

$theDoc="../../xml/techList.html";
// The fopen() line works as expected, creating a new document techList.html and overwriting an existing document.
$newDoc=fopen($theDoc,"w");
//The fwrite() doesn't. Error message (type  appears.
$write=fwrite($theDoc,"If you can read this, it works.");
//the next line returns "write is "
echo "write is $write";
//this line also generates a type 8 error message.
$newDoc=fclose($theDoc);

 

When I have to ask for help, it's nearly always because there's something very basic and stupid I've overlooked. I suspect that this is also the case here. So, if you can tell me what I've missed, I'd be very happy to getting around to the business of kicking myself and getting it right.

Link to comment
Share on other sites

<?php
$theDoc="../../xml/techList.html";
// The fopen() line works as expected, creating a new document techList.html and overwriting an existing document.
$newDoc=fopen($theDoc,"w");
//The fwrite() doesn't. Error message (type  appears.
fwrite($theDoc,"If you can read this, it works.");
//this line also generates a type 8 error message.
$newDoc=fclose($theDoc);
?>

Link to comment
Share on other sites

Nope, it's not that basic. I did see the problem, though, and correct it after taking a short nap. Thanks for your help, though - I'm sure I'll be back again. The other question I have, then:

I'm new here, so how does one close a thread where the problem is solved?

 

<?php
...
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.