note 84180 added to function.file-put-contents

From: Date: Wed, 02 Jul 2008 12:25:25 +0000
Subject: note 84180 added to function.file-put-contents
Groups: php.notes 
Request: Send a blank email to php-notes+get-141065@lists.php.net to get a copy of this message
File put contents fails if you try to put a file in a directory that doesn't exist. This creates the directory. <?php function file_force_contents($dir, $contents){ $parts = explode('/', $dir); $file = array_pop($parts); $dir = ''; foreach($parts as $part) if(!is_dir($dir .= "/$part")) mkdir($dir); file_put_contents("$dir/$file", $contents); } ?> ---- Server IP: 209.41.74.194 Probable Submitter: 76.120.157.167 ---- Manual Page -- http://www.php.net/manual/en/function.file-put-contents.php Edit -- https://master.php.net/note/edit/84180 Del: integrated -- https://master.php.net/note/delete/84180/integrated Del: useless -- https://master.php.net/note/delete/84180/useless Del: bad code -- https://master.php.net/note/delete/84180/bad+code Del: spam -- https://master.php.net/note/delete/84180/spam Del: non-english -- https://master.php.net/note/delete/84180/non-english Del: in docs -- https://master.php.net/note/delete/84180/in+docs Del: other reasons-- https://master.php.net/note/delete/84180 Reject -- https://master.php.net/note/reject/84180 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#141065) next »