Created
March 20, 2018 05:51
-
-
Save p208p2002/2bdee9c7495537554f2a4e9e85c972fe to your computer and use it in GitHub Desktop.
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\Services; | |
| use DB; | |
| use Exception; | |
| class ImageService | |
| { | |
| public function store($imgFile){ | |
| if($imgFile==null) | |
| return back(); | |
| $destinationPath = public_path().'/img/'; | |
| $filename = $imgFile->getclientoriginalname(); | |
| $filetype=$imgFile->getMimeType(); | |
| if($filetype!='image/jpeg'){ //格式jpg | |
| throw new Exception("圖片格式錯誤"); | |
| } | |
| $unique_name = md5($filename. time()).'.jpg'; | |
| $imgFile->move($destinationPath,$unique_name); | |
| //store | |
| $fileurl='/img/'.$unique_name; | |
| DB::table('imgtable')->insert( | |
| ['filename' => $unique_name, | |
| 'filename_origin' => $filename, | |
| 'path'=> $fileurl] | |
| ); | |
| return $fileurl; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment