private static function get_writable_file($file_path) { $f = new File($file_path); //Ensure that all symlinks are followed to the end while ($f->is_link()) { $f = $f->readlink(); } if (!$f->exists()) { //Just to make sure $real_path = $f->realPath(); $real_file = new File($real_path); //Grab the path information $pinfo = $real_file->pathinfo(); $directory = $pinfo->dirname; //Ensure the directory exists $dfile = new File($directory); if (!$dfile->exists()) { $dfile->mkdir(0777, true); } //Try to touch the file $real_file->touch(); } if ($f->is_dir()) { return null; } if ($f->is_writable()) { return $f; } return null; }