Skip to content

Instantly share code, notes, and snippets.

@naosim
Last active July 5, 2017 22:01
Show Gist options
  • Save naosim/3f18a045222faffd4bf80903e42b8bef to your computer and use it in GitHub Desktop.
Save naosim/3f18a045222faffd4bf80903e42b8bef to your computer and use it in GitHub Desktop.
[PHP]include php a file from web
<?php
function includeFromWeb($url, $root = '.') {
$file = $root . '/vendor/' . explode('//', $url)[1];
$dir = substr($file, 0, strrpos($file, '/'));
if(!file_exists($file)) {
if(!file_exists($dir)) {
mkdir($dir, 0777, true);
}
$text = trim(file_get_contents($url));
if(strpos($text, '<?php') === false) {
throw new RuntimeException("Not PHP FILE: " . $url);
}
file_put_contents($file, $text);
}
include_once $file;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment