Skip to content

Instantly share code, notes, and snippets.

@rrrhys
Created April 1, 2019 11:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rrrhys/e468073d97072c983595cd7e35bb5f42 to your computer and use it in GitHub Desktop.
Save rrrhys/e468073d97072c983595cd7e35bb5f42 to your computer and use it in GitHub Desktop.
Route::get('/external_resource', function(\Illuminate\Http\Request $request){
$resource = $request->get("resource");
$options = array('http' => array('user_agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36'));
$context = stream_context_create($options);
$f = file_get_contents($resource, false, $context);
$finfo = new finfo(FILEINFO_MIME);
$contenttype = $finfo->buffer($f);
header("Content-Type: " . $contenttype); //HTTP 1.1
echo $f;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment