Created
May 11, 2014 19:37
-
-
Save ahmadshah/f1000eaebea0f9b7c37d to your computer and use it in GitHub Desktop.
UploadableTrait.php
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 namespace Eisai\Support\Traits; | |
use Rhumsaa\Uuid\Uuid; | |
use Illuminate\Support\Facades\File; | |
use Symfony\Component\HttpFoundation\File\UploadedFile; | |
trait UploadableTrait { | |
/** | |
* [store description] | |
* @return [type] [description] | |
*/ | |
public function move(UploadedFile $file) | |
{ | |
$path = $this->getUploadPath(); | |
$extension = $file->getClientOriginalExtension(); | |
$filename = Uuid::uuid1().".{$extension}"; | |
$file->move($path, $filename); | |
return $path."/{$filename}"; | |
} | |
/** | |
* [delete description] | |
* @return [type] [description] | |
*/ | |
public function remove($file) | |
{ | |
return File::delete($file); | |
} | |
/** | |
* [setUploadPath description] | |
* @param [type] $path [description] | |
*/ | |
protected function getUploadPath() | |
{ | |
return public_path().'/uploads'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment