Search
 
SCRIPT & CODE EXAMPLE
 

PHP

file upload using ajax in laravel

<?php

namespace AppHttpControllers;

use IlluminateHttpRequest;
use AppModelsImage;

class ImageController extends Controller
{
    public function index()
    {

      return view('images');
    }

    public function storeImage(Request $request)
    {
        $request->validate([
          'file' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
        ]);

        $image = new Image;

        if ($request->file('file')) {
            $imagePath = $request->file('file');
            $imageName = $imagePath->getClientOriginalName();

            $path = $request->file('file')->storeAs('uploads', $imageName, 'public');
        }

        $image->name = $imageName;
        $image->path = '/storage/'.$path;
        $image->save();

        return response()->json('Image uploaded successfully');
    }
}
Comment

PREVIOUS NEXT
Code Example
Php :: Download any version of xampp 
Php :: image upload in php code with databases 
Php :: wordpress popular posts query 
Php :: yii1 refresh cache schema 
Php :: PHP MySQL Insert Multiple Records 
Php :: php - = 
Php :: object of class stdclass could not be converted to string php laravel 
Php :: laravel function 
Php :: random string number generator in php codeigniter 
Php :: resource route laravel 8 
Php :: laravel custom validation rules 
Php :: find substring php 
Php :: orderby not working with groupby laravel 
Php :: laravel filter get pagiination does not flter Appending To Pagination Links 
Php :: php error handling 
Php :: how to manually remove cache in laravel 
Php :: composer install phpWord 
Php :: how to get the size of an uploaded file in laravel 
Php :: Using the PHPExcel library to read an Excel file and transfer the data into a database 
Php :: laravel merge two arrays helper 
Php :: php prepared statements 
Php :: error laravel 404 in server 
Php :: unique validation laravel 
Php :: upload image to database laravel 8 
Php :: run composer with specific php version 
Php :: MySQL table in new page after click php 
Php :: A Livewire component was not found 
Php :: append single quote around variable in php string 
Php :: italic text in laravel notification 
Php :: php strip url of all invalid characters 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =