note 115151 deleted from function.mkdir by crell

From: Date: Wed, 29 Jun 2022 19:17:03 +0000
Subject: note 115151 deleted from function.mkdir by crell
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-218714@lists.php.net to get a copy of this message
Note Submitter: haclong ---- If you are using the SPL FileInfo object and then try to create the path with mkdir, don't forget that mkdir expects a string as the first argument and NOT an object... I have forgotten that very important rules and get only a permission deny to mkdir to create new directories but in fact, the issue was the fact that i wasn't passing a string to mkdir $my_file = new SplFileInfo('path/to/file.txt') ; // get path from file $parent = $my_file->getPathInfo() ; // check if path is directory or not if($parent->isDir()) { // create / open file.txt file } else { // if path/to does not exists, create the directory recursively mkdir($parent, 0755, true) ; // THIS WON'T WORK because $parent is a SplFileInfo object. // instead, get the path as a string $path = $parent->getPathname() ; mkdir($path, 0755, true) ; // THIS WILL WORK }

« previous php.notes (#218714) next »