fwrite不写作 [英] fwrite not writing

查看:62
本文介绍了fwrite不写作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 $fp = fopen('log.txt', 'w');
 fwrite($fp, 'Missing gallery image for: ' . $row['toolbar_id'] . '\n');

上面的代码未写入文件. $row['toolbar_id']是每个循环的a中的值.有什么建议?没有PHP错误,因为在调试该部分后该文件确实打开了.

The code above is not writing to the file. the $row['toolbar_id'] is a value from a for each loop. Any suggestions? There is no PHP error, as the file does open as I have debugged that part.

推荐答案

尝试使用此方法可以确保更多的保证

Try this for extra surety

ini_set('display_errors', 'On');
error_reporting(E_ALL);

$fp = fopen('log.txt', 'ab');
if (false === $fp) {
    throw new RuntimeException('Unable to open log file for writing');
}

$bytes = fwrite($fp, 'Missing gallery image for: ' . $row['toolbar_id'] . PHP_EOL);
printf('Wrote %d bytes to %s', $bytes, realpath('log.txt'));
fclose($fp);

将写"标志( w )更改为追加"( a ),因为不会截断日志文件听起来是个好主意

Changed the "write" flag (w) to "append" (a) as truncating a log file doesn't sound like a great idea

这篇关于fwrite不写作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆