@ -0,0 +1,26 @@ |
||||
<?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]); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,26 @@ |
||||
<?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]); |
||||
} |
||||
} |
||||
} |
||||
} |
After Width: | Height: | Size: 389 KiB |
After Width: | Height: | Size: 389 KiB |
After Width: | Height: | Size: 76 KiB |
After Width: | Height: | Size: 394 KiB |
After Width: | Height: | Size: 394 KiB |
After Width: | Height: | Size: 460 KiB |
After Width: | Height: | Size: 78 KiB |
After Width: | Height: | Size: 389 KiB |
After Width: | Height: | Size: 389 KiB |