TOP ▲ itcore TOP プログラムパーツ

uOpendirArrayCreate 配列に入っているファイル名をディレクトリに作成する。既にあれば上書き。 | itcore 2017年

PHP関数

<?php
// 配列に入っているファイル名をディレクトリに作成する。既にあれば上書き。
function uOpendirArrayCreate($dir, $a_fname_create) {
  foreach ($a_fname_create as $fname => $data) {
    file_put_contents("$dir/$fname", $data);
  }
}
?>

単体テスト 実行

<?php include "uOpendirArrayCreate.func"; ?>
<?php
  $dir = "/tmp";
  $a_fname_create = array();
  $a_fname_create["test_1.txt"] = "てすと1";
  $a_fname_create["test_2.txt"] = "てすと2";
  uOpendirArrayCreate($dir, $a_fname_create);
  echo shell_exec("ls -l /tmp/test_1.txt") . "<br>\n";
  echo shell_exec("cat /tmp/test_1.txt") . "<br>\n";
  echo shell_exec("ls -l /tmp/test_2.txt") . "<br>\n";
  echo shell_exec("cat /tmp/test_2.txt") . "<br>\n";
?>
<?php include "uJsClose.func"; print(uJsClose()); // 閉じるボタン ?>