You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
1.1 KiB
27 lines
1.1 KiB
2 years ago
|
<?php
|
||
|
|
||
|
namespace App\Http\Controllers;
|
||
|
|
||
|
use Illuminate\Http\Request;
|
||
|
|
||
|
class ImageUploadController extends Controller
|
||
|
{
|
||
|
public function storeImage(Request $request)
|
||
|
{
|
||
|
if ($request->hasFile('upload')) {
|
||
|
$finfo = finfo_open(FILEINFO_MIME_TYPE); // Return MIME type a la the 'mimetype' extension
|
||
|
$mimeType = finfo_file($finfo, $request->file('upload'));
|
||
|
finfo_close($finfo);
|
||
|
if ($mimeType == 'image/jpeg' || $mimeType == 'image/png' || $mimeType == 'image/svg+xml' || $mimeType == 'image/gif' || $mimeType == 'image/webp') {
|
||
|
$originName = $request->file('upload')->getClientOriginalName();
|
||
|
$fileName = pathinfo($originName, PATHINFO_FILENAME);
|
||
|
$extension = $request->file('upload')->getClientOriginalExtension();
|
||
|
$fileName = $fileName . '_' . time() . '.' . $extension;
|
||
|
$request->file('upload')->move(public_path('images/media'), $fileName);
|
||
|
$url = asset('images/media/' . $fileName);
|
||
|
return response()->json(['fileName' => $fileName, 'uploaded'=> 1, 'url' => $url]);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|