note 115945 added to function.file-put-contents
| From: | klunker dot roox at gmail dot com | Date: | Fri, 17 Oct 2014 10:47:49 +0000 |
| Subject: | note 115945 added to function.file-put-contents | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-200672@lists.php.net to get a copy of this message | ||
if path to the file not exist function file_put_contents can't create it. This simple function
make it on UNIX-based and Windows servers.
<?php
function file_put_contents_force(){
$args = func_get_args();
$path = str_replace(array('/','\\'), DIRECTORY_SEPARATOR, $args[0]);
$parts = explode(DIRECTORY_SEPARATOR, $path);
array_pop($parts);
$directory = '';
foreach($parts as $part):
$check_path = $directory.$part;
if( is_dir($check_path.DIRECTORY_SEPARATOR) === FALSE) {
mkdir($check_path, 0755);
}
$directory = $check_path.DIRECTORY_SEPARATOR;
endforeach;
call_user_func_array('file_put_contents',$args);
}
?>
----
Server IP: 195.54.192.44
Probable Submitter: 195.189.19.250
----
Manual Page -- http://php.net/manual/en/function.file-put-contents.php
Edit -- https://master.php.net/note/edit/115945
Del: integrated -- https://master.php.net/note/delete/115945/integrated
Del: useless -- https://master.php.net/note/delete/115945/useless
Del: bad code -- https://master.php.net/note/delete/115945/bad+code
Del: spam -- https://master.php.net/note/delete/115945/spam
Del: non-english -- https://master.php.net/note/delete/115945/non-english
Del: in docs -- https://master.php.net/note/delete/115945/in+docs
Del: other reasons-- https://master.php.net/note/delete/115945
Reject -- https://master.php.net/note/reject/115945
Search -- https://master.php.net/manage/user-notes.php