note 82805 modified in function.fopen by danbrown
| From: | danbrown@php.net | Date: | Mon, 08 Jun 2009 23:31:07 +0000 |
| Subject: | note 82805 modified in function.fopen by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-156539@lists.php.net to get a copy of this message | ||
Also a small function useful for backup for example. It's a mixed between the fopen() and the
mkdir() functions.
This function opens a file but also make the path recursively where the file is contained. This is
helpful for ending to finish with "No such file or directory in" errors
<?php
function fopen_recursive($path, $mode, $chmod=0755){
preg_match('
^(.+)/([a-zA-Z0-9]+\.[a-z]+)$i', $path, $matches);
$directory = $matches[1];
$file = $matches[2];
if (!is_dir($directory)){
if (!mkdir($directory, $chmod, 1)){
return FALSE;
}
}
return fopen ($path, $mode);
}
?>
--was--
Also a small function useful for backup for example. It's a mixed between the fopen() and the
mkdir() functions.
This function opens a file but also make the path recursively where the file is contained. This is
helpful for ending to finish with "No such file or directory in" errors
function fopen_recursive($path, $mode, $chmod=0755){
preg_match('^(.+)/([a-zA-Z0-9]+\.[a-z]+)$i', $path, $matches);
$directory = $matches[1];
$file = $matches[2];
if (!is_dir($directory)){
if (!mkdir($directory, $chmod, 1)){
return FALSE;
}
}
return fopen ($path, $mode);
}
http://php.net/manual/en/function.fopen.php