0

嘿,我想知道为什么我下面的代码只写第一个文件而不写第二个文件

$counterFile = 'counter.log';
$counterFileBU = 'counterBU.log';

if(!is_writable($counterFile)) {
    $count = 'WErr';
}
else {
    $count = file_get_contents($counterFile);
    $count++;
    file_put_contents($counterFile, $count);
    file_put_contents($counterFileBU, $count . ' @ ' . date("F j, Y, g:i a"));
}

任何帮助都会很棒!

4

1 回答 1

1

如果不满足此条件,您的代码将不会运行并且不会输出任何内容?

 if(!is_writable($counterFile)) {

你应该尝试触发一些错误

$counterFile = __DIR__ . '/counter.log';
$counterFileBU = __DIR__ . '/counterBU.log';

touch($counterFile);
touch($counterFileBU);

if(!is_writable($counterFile) || !is_writable($counterFileBU) ) {
   throw new Exception("Not Writable");
}
于 2012-10-10T14:12:20.063 回答