note 50323 rejected from function.mkdir by betz
| From: | betz@php.net | Date: | Sun, 05 Jun 2005 16:27:06 +0000 |
| Subject: | note 50323 rejected from function.mkdir by betz | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-89959@lists.php.net to get a copy of this message | ||
Note Submitter: jay dot kamminga at home dot nl
----
I was looking for a function called mkfile, since it doesn't exist:
<?
function mkfile($filename, $mode = 0777, $contents = null) {
$dir = preg_replace("/^(.*\/)[^\/]+$/", "\\1", $filename);
if (!is_dir($dir)) { trigger_error("mkfile() failed, no such directory
<strong>{$dir}</strong>, ", E_USER_WARNING); return(false); }
if (file_exists($filename)) { trigger_error("mkfile() failed (File exists)",
E_USER_WARNING); return(false); }
if (is_array($contents)) $contents = implode("\n", $contents);
if ($fp = fopen($filename, "w")) {
if (is_null($contents)) {
return($fp);
} else {
fwrite($fp, $contents);
chmod($filename, $mode);
fclose($fp);
return(true);
}
} else { trigger_error("mkfile() failed (Wrong file permissions)", E_USER_WARNING);
return(false); }
} // mkfile.
?>