33
44use Illuminate \Support \Facades \File ;
55use Intervention \Image \Facades \Image ;
6+ use Illuminate \Http \UploadedFile ;
67
78/**
89 * Class ImageUploader
@@ -41,7 +42,7 @@ public function __construct($uploaded_file, $destination = null, $resize = false
4142 {
4243 $ this ->setUploadedFile ($ uploaded_file );
4344 $ this ->setDestination ($ destination );
44- $ this -> setThumb ( ' thumb_ ' . $ this -> getFileName ());
45+
4546
4647 $ this ->resize = $ resize ;
4748 $ this ->imageWidth = $ imageWidth ;
@@ -53,7 +54,6 @@ public function __construct($uploaded_file, $destination = null, $resize = false
5354 {
5455 File::makeDirectory (public_path ($ this ->destination ), $ mode = 0777 , true );
5556 }
56-
5757 parent ::__construct ();
5858 }
5959
@@ -76,8 +76,9 @@ public function setThumb($thumb)
7676 /**
7777 *
7878 */
79- public function upload ()
79+ public function upload (UploadedFile $ uploadedFile )
8080 {
81+ $ this ->setThumb ('thumb_ ' .$ this ->getFileName ());
8182 $ this ->uploadImageFile ($ this ->getFileName ());
8283 $ this ->uploadImageThumb ($ this ->getThumb ());
8384 }
@@ -96,10 +97,10 @@ public function uploadImageFile($filename)
9697 return Image::make ($ this ->getUploadedFile ()->getRealPath ())
9798 ->resize ($ this ->imageWidth , $ this ->imageHeight , function ($ constraint ) {
9899 $ constraint ->aspectRatio ();
99- })->save (public_path ($ this ->getDestination () . $ filename ));
100+ })->save (public_path ($ this ->getDestination () .' / ' . $ filename ));
100101 }else {
101102 return Image::make ($ this ->getUploadedFile ()->getRealPath ())
102- ->save (public_path ($ this ->getDestination () . $ filename ));
103+ ->save (public_path ($ this ->getDestination () . ' / ' . $ filename ));
103104 }
104105 }
105106 /**
@@ -112,16 +113,15 @@ public function uploadImageThumb($thumb)
112113
113114 if ($ width > $ this ->thumbWidth )
114115 {
115- Image::make ($ this ->getUploadedFile ()->getRealPath ())
116- ->resize ($ this ->thumbWidth , $ this ->thumbHeight , function ($ constraint ) {
117- $ constraint ->aspectRatio ();
118- })
119- ->save (public_path ($ this ->getDestination () . $ thumb ));
116+ return Image::make ($ this ->getUploadedFile ()->getRealPath ())
117+ ->resize ($ this ->thumbWidth , $ this ->thumbHeight , function ($ constraint ) {
118+ $ constraint ->aspectRatio ();
119+ })
120+ ->save (public_path ($ this ->getDestination () . ' / ' . $ thumb ));
120121 }else {
121122 return Image::make ($ this ->getUploadedFile ()->getRealPath ())
122123 ->save (public_path ($ this ->getDestination () .'/ ' . $ thumb ));
123124 }
124- return $ thumb ;
125125 }
126126
127127}
0 commit comments