Skip to content

Instantly share code, notes, and snippets.

@s-hiroshi
Created May 14, 2012 06:31
Show Gist options
  • Select an option

  • Save s-hiroshi/2692173 to your computer and use it in GitHub Desktop.

Select an option

Save s-hiroshi/2692173 to your computer and use it in GitHub Desktop.
PHP > create file
/**
* create file
*/
function createFile($dir, $file) {
$html = <<<HTML
<!DOCTYPE HTML>';
<html lang="en">';
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<p>file create template.</p>
</body>
</html>
HTML;
$html = mb_convert_encoding($html, "UTF-8");
// ファイル出力処理
$direcName = $dir;
$fileName = $file;
$filePath = $direcName . $fileName;
$fp = fopen($filePath, "w") or die("can not open file.");
flock($fp, LOCK_EX);
fputs($fp, $html);
flock($fp, LOCK_UN);
fclose($fp);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment