0

以下の私のコードが最初のファイルだけを書き込んでいて、2番目のファイルを書き込んでいないのはなぜだろうと思っています

$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 に答える