Pyh.conf’25: a new PHP conference for the Russian-speaking community

Voting

: nine plus zero?
(Example: nine)

The Note You're Voting On

vaneatona at gmail dot com
8 years ago
I'm updating a function that was posted, as it would fail if there was no directory. It also returns the final value so you can determine if the actual file was written.

public static 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);
}

return file_put_contents("{$dir}{$file}", $contents);
}

<< Back to user notes page

To Top