Last active
July 5, 2017 22:01
-
-
Save naosim/3f18a045222faffd4bf80903e42b8bef to your computer and use it in GitHub Desktop.
[PHP]include php a file from web
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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