-
-
Save ItsSalman99/469d437bd57bd27c771fad4345750b1a to your computer and use it in GitHub Desktop.
Image Upload Code (PHP LARAVEL)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Traits; | |
trait ImageUploadTrait | |
{ | |
function upload_image($path, $file) | |
{ | |
// dd($uploaded_file); | |
if ($file) { | |
$filenameWithExt = $file->getClientOriginalName(); | |
$filename = pathinfo($filenameWithExt, PATHINFO_FILENAME); | |
$extension = $file->getClientOriginalExtension(); | |
$fileNameToStore = 'image_' . $filename . '_' . time() . '.' . $extension; | |
$file->move(public_path($path), $fileNameToStore); | |
return request()->getSchemeAndHttpHost() . $path . '' . $fileNameToStore; | |
} | |
return ''; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment