28 lines
629 B
PHP
28 lines
629 B
PHP
|
<?php
|
||
|
|
||
|
namespace App\Http\Controllers;
|
||
|
|
||
|
use Illuminate\Http\Response;
|
||
|
use Illuminate\Support\Facades\File;
|
||
|
|
||
|
class ImageController extends Controller
|
||
|
{
|
||
|
//'/resources/app/uploads/{filename}'
|
||
|
public function getFile($filename)
|
||
|
{
|
||
|
$path = resource_path() . '/app/uploads/' . $filename;
|
||
|
|
||
|
if (!File::exists($path)) {
|
||
|
return response()->json(['message' => 'Image not found.'], 404);
|
||
|
}
|
||
|
|
||
|
$file = File::get($path);
|
||
|
$type = File::mimeType($path);
|
||
|
|
||
|
$response = Response::make($file, 200);
|
||
|
$response->header("Content-Type", $type);
|
||
|
|
||
|
return $response;
|
||
|
}
|
||
|
}
|