0
$fp = fopen('a.html', 'w');
fwrite($fp, 'Done');

works well but

$fp = fopen('b.php', 'w');
fwrite($fp, 'Done');

isn't working. What can be the possible solution?

Thanks in avance.

Update: 1: echo fwrite($fp, 'Done') prints 4. No errors. And the file remains unchanged. Doesn't fwrite() works with php files? 2: I am doing this in my local server and I have all the permissions.

Cool Brain
  • 647
  • 2
  • 8
  • 14
  • 1
    Define "isn't working". Errors? How are you checking the result? In general: PHP doesn't care about file name extensions. At all. `.php` is not the source of any problem here. – deceze Feb 11 '13 at 07:06
  • You're not doing any error checking. fopen and fwrite can both fail and will return FALSE if they do. You need to check for false rather than just assume the operation worked. Also, in what way doesn't it work? What error messages are you getting? If you have error reporting turned on you should be getting error messages displayed or logged somewhere. – GordonM Feb 11 '13 at 07:32
  • It's working now. Two `b.php` file was the problem. Thank you guys for your valuable time. – Cool Brain Feb 11 '13 at 08:05

2 Answers2

1
$fp = fopen('a.html', 'w');
fwrite($fp, 'Done');
fclose($fp);


$fp = fopen('b.php', 'w');
fwrite($fp, 'Done');
fclose($fp);

use fclose($fp);

Ripa Saha
  • 2,532
  • 6
  • 27
  • 51
0

check Your file permission maybe you haven't permission for Write on this file

mohammad mohsenipur
  • 3,218
  • 2
  • 17
  • 22