Skip to content

Instantly share code, notes, and snippets.

@yus-ham
Created January 28, 2019 22:32
Show Gist options
  • Save yus-ham/fc623aaa2b144395570f54705da6ab92 to your computer and use it in GitHub Desktop.
Save yus-ham/fc623aaa2b144395570f54705da6ab92 to your computer and use it in GitHub Desktop.
<body style=width:900px><pre>
<?php
error_reporting(E_ALL);
createFileRecursive([
'dir' => __DIR__,
'name' => '.nomedia',
'contents' => '',
'excludes' => [
__DIR__.'/sid-3',
__DIR__.'/vendor',
],
]);
function createFileRecursive($ops) {
extract($ops);
$files = new FileSystemIterator($dir);
foreach ($files as $file) {
if (!$file->isDir())
continue;
if (in_array($files->current(), (array)$excludes)) {
$echo_w[] = '<span style=color:#ffaa00>[!] dir excluded: '. $files->current() .'</span><br>';
continue;
}
$ops['dir'] = $files->current();
createFileRecursive($ops);
}
$file = $dir .'/'. $name;
$ok = file_put_contents($file, $contents);
if ($ok !== false) {
print '<span style=color:#007733>[ok] file created: '. $file .'</span><br>';
} else {
$err = error_get_last();
print_r($err);
$echo_w[] = $err['message'];
}
isset($echo_w) && print implode('', $echo_w);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment