Created
June 30, 2015 09:07
-
-
Save johnhout/b002acccffb93c8a1d6f to your computer and use it in GitHub Desktop.
Trait for simple file uploading for 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 | |
use Symfony\Component\HttpFoundation\File\UploadedFile; | |
trait SimpleUploadTrait { | |
/** | |
* Upload the file with slugging to a given path | |
* | |
* @param UploadedFile $image | |
* @param $path | |
* @return string | |
*/ | |
public function uploadFile(UploadedFile $image, $path) | |
{ | |
$extension = $image->getClientOriginalExtension(); | |
$name = pathinfo($image->getClientOriginalName(), PATHINFO_FILENAME); | |
$image_name = str_slug(date('Y-m-d-h-i-s') . $name . str_random()) . '.' . $extension; | |
$image->move($path, $image_name); | |
return $image_name; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment