fwrite vs file_put_contents

Associate
Joined
27 Jun 2006
Posts
1,473
Can anyone tell me the difference (apart from the PHP5 only for php_put_contents).

I wrote a script that should open a file (using fopen) and then take a variable and write it out before closing the file handle (using fwrite and fclose) but do you think it would write it - would it hell!

Kept getting a not a valid stream (I think that was the error) meaning the filehandle wasn't there (even though it created a blank file!)

Scratched my head and then tried php_put_contents and it worked a treat.

Glad it worked but cannot figure out why the fopen/fwrite/fclose commands didn't work.

Any ideas?
 
I went through every possible combination of fwrite - check out my hair, torn out in clumps!!!

The script could write to the right place as when I called fopen it wrote the filename ready to get the data but do you think it would write to the file....would it hell!

Anyway, happy that file_put_contents did it magic....saved me hours more pain!
 
Back
Top Bottom