Skip to content

Instantly share code, notes, and snippets.

@s-hiroshi
Created September 12, 2012 04:57
Show Gist options
  • Save s-hiroshi/3704377 to your computer and use it in GitHub Desktop.
Save s-hiroshi/3704377 to your computer and use it in GitHub Desktop.
PHP > file
// ファイルの権限(パーミッション)を表示する
<?php
$data = array(
'file' => 'sample.txt',
);
if (file_exists($data['file'])) {
$data['exists'] = 'exists';
} else {
$data['exists'] = 'no exists';
}
if (is_readable($data['file'])) {
$data['readable'] = 'readable';
} else {
$data['readable'] = 'no readable';
}
if (is_writable($data['file'])) {
$data['writable'] = 'writable';
} else {
$data['writable'] = 'no writable';
}
if (is_executable($data['file'])) {
$data['execute'] = 'executable';
} else {
$data['execute'] = 'no executable';
}
var_dump($data);
[ 1347425170.002]
[ 1347425190.361]
[ 1347425207.422]
<?php
$filename = 'sample.txt';
if (file_exists($filename) && !is_writable($filename)
|| !is_writable(dirname($filename))) {
echo "Error";
}
$fp = fopen($filename, 'a') or dir('ファイルを開けません');
fwrite($fp, sprintf("[%' 15.3f]" . "\n", microtime(true)));
fclose($fp);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment