Example #1
0
 /**
  * ディレクトリが存在しない場合、作成を試みてファイル作成を行う
  *
  * <code>
  * #ディレクトリを全て作成し、test.datを作成。
  * File::buildPutFile('cache/te/ki/tou/na/folder/test.dat','コンテンツ');
  * </code>
  *
  * @param string $filepath ファイルのパス
  * @param string $content 書き込む内容
  * @param string $hook_func ファイル、ディレクトリ作成ごとに実行する関数を指定。
  * @return resouce ファイルポインタ
  */
 public static function buildPutFile($filepath, $content, $hook_func = '')
 {
     File::buildMakeDir(dirname($filepath), $hook_func);
     if ($fp = File::buildFileOpen($filepath)) {
         flock($fp, LOCK_EX);
         ftruncate($fp, 0);
         fputs($fp, $content);
         flock($fp, LOCK_UN);
         fclose($fp);
         if ($hook_func) {
             call_user_func($hook_func, 'make_file', $filepath);
         }
         return true;
     }
     return false;
 }