#29 ファイルにデータを書き込む (3)

 
fclose( )
  fclose($fp) ファイルポインターリソースを解放( 終了処理 )
 
  ( 処理まとめ )
 
$testFile = "test.dat";
$contents = "こんにちは!";

if (is_writable($testFile)) {

    // ファイルをオープンできたか?
    if (!$fp = fopen($testFile, "a")) {
        echo "colud not open!";
        exit;
    }

    // 書き込めたか?
    if (fwrite($fp, $contents) === false) {
        echo "could not write!";
        exit;
    }

    echo "success!";

    // 終了処理
    fclose($fp);

} else {
    echo "not writable!";
    exit;
}
 

PAGE TOP

< 前へ 目次に戻る 次へ >