Skip to content

Instantly share code, notes, and snippets.

@nonsalant
Last active November 9, 2015 01:44
Show Gist options
  • Save nonsalant/6e5b995512d505b3b008 to your computer and use it in GitHub Desktop.
Save nonsalant/6e5b995512d505b3b008 to your computer and use it in GitHub Desktop.
echoFromFile.php
function echoFromFile($fileName, $run, $data) {
if (!is_dir('temp')) {
mkdir('temp');
}
file_put_contents($fileName, $data);
if ($run===1) {
include($fileName);
}
else {
readfile($fileName);
};
rrmdir('temp');
}
function rrmdir($dir) {
if (is_dir($dir)) {
$objects = scandir($dir);
foreach ($objects as $object) {
if ($object != "." && $object != "..") {
if (filetype($dir."/".$object) == "dir") rmdir($dir."/".$object); else unlink($dir."/".$object);
}
}
reset($objects);
rmdir($dir);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment