1<?php
2
3namespace App\Http\Controllers\simple_image_upload;
4
5use Illuminate\Http\Request;
6use App\Http\Controllers\Controller;
7use Validator,Redirect,Response,File;
8use App\Photo;
9
10class ImageUploadController extends Controller
11{
12 //
13 public function index()
14 {
15 return view('simple_image_upload.index');
16 }
17
18 public function store(Request $request)
19 {
20 request()->validate([
21 'profile_image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
22 ]);
23 if ($files = $request->file('profile_image')) {
24 // Define upload path
25 $destinationPath = public_path('/profile_images/'); // upload path
26 // Upload Orginal Image
27 $profileImage = date('YmdHis') . "." . $files->getClientOriginalExtension();
28 $files->move($destinationPath, $profileImage);
29
30 $insert['image'] = "$profileImage";
31 // Save In Database
32 $imagemodel= new Photo();
33 $imagemodel->photo_name="$profileImage";
34 $imagemodel->save();
35 }
36 return back()->with('success', 'Image Upload successfully');
37
38 }
39}
40
1 foreach ($request['contact'] as $value) {
2 $name = time() . rand(1000, 9999) . $value['image']->getClientOriginalName();
3 $value['image']->move(public_path('/src/admin/assets/uploader/workImage'), $name);
4 }
1// Image uploaad laravel
2if (!empty($request->files) && $request->hasFile('image')) {
3 $input1 = array();
4 $upload_path = 'storage/uploads/customers/';
5 $old_file = $upload_path . '/' . $input['old_image'];
6 if (Storage::exists($old_file)) {
7 //delete previous file
8 unlink($old_file);
9 }
10 $file = $request->file('image');
11 $file_name = $file->getClientOriginalName();
12 $type = $file->getClientOriginalExtension();
13 $real_path = $file->getRealPath();
14 $size = $file->getSize();
15 $size_mbs = ($size / 1024) / 1024;
16 $mime_type = $file->getMimeType();
17
18 $file_temp_name = 'profile_' . time() . '.' . $type;
19 $old_file = $upload_path . '/' . $file_temp_name;
20
21 $path = storage_path() . '/app/public/uploads/customers/' . $file_temp_name;
22 $img = Image::make($file)->resize(300, 300);
23 $img->save($path);
24 $input1['image'] = $file_temp_name;
25}