note 82805 deleted from function.fopen by cmb
| From: | cmb@php.net | Date: | Fri, 09 Sep 2016 22:35:53 +0000 |
| Subject: | note 82805 deleted from function.fopen by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-206552@lists.php.net to get a copy of this message | ||
Note Submitter: webmaster at myeshop dot fr
----
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);
}
?>