开发者

Can't save text to a file

开发者 https://www.devze.com 2023-03-08 14:11 出处:网络
I have the following sequence of code: $fp = fopen(\'script.sh\', \'wt\'); fwrite($fp, \'some text\'); fclose($fp);

I have the following sequence of code:

$fp = fopen('script.sh', 'wt');
fwrite($fp, 'some text');
fclose($fp);

Now this should write some text to script.sh, simple and clear and worked for a while. But since yesterday script.sh is always empty, even though some text is not empty at all. The funny part is that no errors are returned. Also if I type manually something inside script.sh and then run the code script开发者_如何转开发.sh is empty again.

Permissions are 777. The file is correct (if I delete it it says that the file does not exist).


There is no FOPEN mode 'wt' so it will default to WRITE as defined in the PHP doc:

Open for writing only; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it.

http://uk.php.net/manual/en/function.fopen.php

Open the file with either APPEND (a) or WRITE (w) mode in order to write data to the file correctly.


is it 'w+' instead of 'wt'?


Run out of space and the file could not be saved any more. Works ok now.

0

精彩评论

暂无评论...
验证码 换一张
取 消