Answers for "how to upload image in laravel"

PHP
1

image validate in laravel validater

$this->validate($request, ['file' => 'image|mimes:jpeg,png,jpg,gif,svg|max:2048',]);
Posted by: Guest on October-20-2020
4

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');
 
    }
}
Posted by: Guest on October-21-2020
0

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;
}
Posted by: Guest on September-03-2021
0

upload image to database laravel 8

$request->image->storeAs('images', $imageName);  // storage/app/images/file.png
Posted by: Guest on August-25-2021

Code answers related to "how to upload image in laravel"

Browse Popular Code Answers by Language