Created
August 16, 2017 04:46
-
-
Save jmrashed/1f41dacb16ddcad74b8d9b33e0a595e4 to your computer and use it in GitHub Desktop.
File/ Image Upload in Laravel
This file contains 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 | |
public function uploadImage($fileInputField, $uploadFolder, $fileName = '', $create_thumb = false, $photoIndex = false) { | |
$uploadedFileName = ''; | |
if (Input::file($fileInputField)) { | |
$fileName = preg_replace('/\s*/', '', $fileName); | |
$fileName = strtoupper($fileName); | |
$fileInfo = Input::file($fileInputField); | |
if (is_array($fileInfo)) | |
$fileInfo = $fileInfo[$photoIndex]; | |
$uploadedFileName = $fileName . '.' . $fileInfo->getClientOriginalExtension(); | |
//Upload Thumbnail Image | |
if ($create_thumb) { | |
$upload_thumb_path = public_path($uploadFolder . '/thumbs'); | |
if (!File::exists($upload_thumb_path)) { | |
File::makeDirectory($upload_thumb_path, $mode = 0777, true, true); | |
} | |
Image::make($fileInfo->getRealPath())->resize(150, 150)->save($upload_thumb_path . '/' . $uploadedFileName); | |
} | |
//Upload Original Image | |
$upload_path = public_path($uploadFolder); | |
if (!File::exists($upload_path)) { | |
File::makeDirectory($upload_path, $mode = 0777, true, true); | |
} | |
$fileInfo->move($upload_path, $uploadedFileName); | |
} | |
return $uploadedFileName; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment