Skip to content

Instantly share code, notes, and snippets.

@ItsSalman99
Created January 15, 2025 20:47
Show Gist options
  • Save ItsSalman99/469d437bd57bd27c771fad4345750b1a to your computer and use it in GitHub Desktop.
Save ItsSalman99/469d437bd57bd27c771fad4345750b1a to your computer and use it in GitHub Desktop.
Image Upload Code (PHP LARAVEL)
<?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