image validate in laravel validater
$this->validate($request, ['file' => 'image|mimes:jpeg,png,jpg,gif,svg|max:2048',]);
image validate in laravel validater
$this->validate($request, ['file' => 'image|mimes:jpeg,png,jpg,gif,svg|max:2048',]);
Upload image laravel 6
<?php
namespace App\Http\Controllers\simple_image_upload;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Validator,Redirect,Response,File;
use App\Photo;
class ImageUploadController extends Controller
{
//
public function index()
{
return view('simple_image_upload.index');
}
public function store(Request $request)
{
request()->validate([
'profile_image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
]);
if ($files = $request->file('profile_image')) {
// Define upload path
$destinationPath = public_path('/profile_images/'); // upload path
// Upload Orginal Image
$profileImage = date('YmdHis') . "." . $files->getClientOriginalExtension();
$files->move($destinationPath, $profileImage);
$insert['image'] = "$profileImage";
// Save In Database
$imagemodel= new Photo();
$imagemodel->photo_name="$profileImage";
$imagemodel->save();
}
return back()->with('success', 'Image Upload successfully');
}
}
Image Upload in Laravel
// Image uploaad laravel
if (!empty($request->files) && $request->hasFile('image')) {
$input1 = array();
$upload_path = 'storage/uploads/customers/';
$old_file = $upload_path . '/' . $input['old_image'];
if (Storage::exists($old_file)) {
//delete previous file
unlink($old_file);
}
$file = $request->file('image');
$file_name = $file->getClientOriginalName();
$type = $file->getClientOriginalExtension();
$real_path = $file->getRealPath();
$size = $file->getSize();
$size_mbs = ($size / 1024) / 1024;
$mime_type = $file->getMimeType();
$file_temp_name = 'profile_' . time() . '.' . $type;
$old_file = $upload_path . '/' . $file_temp_name;
$path = storage_path() . '/app/public/uploads/customers/' . $file_temp_name;
$img = Image::make($file)->resize(300, 300);
$img->save($path);
$input1['image'] = $file_temp_name;
}
upload image to database laravel 8
$request->image->storeAs('images', $imageName); // storage/app/images/file.png
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us