Answers for "Image Upload in Laravel"

PHP
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
2

how upload image in arraye in laravel

foreach ($request['contact'] as $value) {
          $name = time() . rand(1000, 9999) . $value['image']->getClientOriginalName();
          $value['image']->move(public_path('/src/admin/assets/uploader/workImage'), $name);
        }
Posted by: Guest on March-27-2021
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

Code answers related to "Image Upload in Laravel"

Browse Popular Code Answers by Language