ファイル存在確認
common
// 存在しない場合は生成
function checkDir($path, $mode = 0777) {
if (!file_exists($path)) {
// 再帰的にディレクトリを生成
if (!@mkdir($path, $mode, true)) return false;
}
return true;
}
コンテンツ取得
common
function fetchContents($url, $datas = array(), $method = 'POST') {
$datas = http_build_query($datas, '', '&');
$header = array(
'Content-Type: application/x-www-form-urlencoded',
'Content-Length: ' . strlen($datas)
);
$context = array(
'http' => array(
'method' => $method,
'header' => implode("\r\n", $header),
'content' => $datas
)
);
return file_get_contents($url, false, stream_context_create($context));
}
ランダム文字列生成
common
function makeRandStr($length = 8) {
$str = array_merge(range('a', 'z'), range('A', 'Z'), range('0', '9'));
$randStr = '';
for ($i = 0; $i < $length; $i++) {
$randStr .= $str[rand(0, count($str))];
}
return $randStr;
}
範囲内の値か確認
common
function checkRangeValue($val, $max, $min = 0) {
return ($val <= $max && $val >= $min) ? true : false;
}