Pictureproxy.php 1.24 KB
Newer Older
1 2 3 4 5
<?php

namespace App\Http\Controllers;

use App;
6
use Illuminate\Http\Request;
7 8 9 10
use Response;

class Pictureproxy extends Controller
{
11 12
    public function get(Request $request)
    {
Dominik Hebeler's avatar
Dominik Hebeler committed
13
        if ($request->filled('url')) {
14 15 16 17 18
            try {
                $arrContextOptions = array(
                    "ssl" => array(
                        "verify_peer"      => false,
                        "verify_peer_name" => false,
Dominik Hebeler's avatar
Dominik Hebeler committed
19
                    ),
20 21
                );
                $file         = file_get_contents($request->input('url'), false, stream_context_create($arrContextOptions));
22
                $responseCode = explode(" ", $http_response_header[0])[1];
23 24 25 26
                $contentType  = "";
                foreach ($http_response_header as $header) {
                    if (strpos($header, "Content-Type:") === 0) {
                        $tmp         = explode(": ", $header);
27 28
                        $contentType = $tmp[1];
                    }
29
                }
30 31
                $response = Response::make($file, $responseCode);
                $response->header('Content-Type', $contentType);
32
            } catch (\ErrorException $e) {
33
                $response = Response::make("", 404);
34 35 36
            }
            return $response;
        }
37 38
    }
}