コード例 #1
0
 protected function imageAvatar()
 {
     $path = 'upload/' . date('Ym/d/');
     $filename = KRandom::getRandStr() . '.jpg';
     if (!File::exists(public_path($path))) {
         File::makeDirectory(public_path($path), 493, true);
     }
     while (File::exists(public_path($path) . $filename)) {
         $filename = KRandom::getRandStr() . '.jpg';
     }
     $this->image->resize(new \Imagine\Image\Box(300, 300))->save(public_path($path) . $filename);
     ImageModel::createUploadedImage($path . $filename, URL::asset($path . $filename));
     $user = AuthModel::user();
     $url = URL::asset($path . $filename);
     if ($user) {
         if ($user->profile) {
             $user->profile->avatar = $url;
             $user->profile->save();
         } else {
             ProfileModel::create(array('user_id' => $user->id, 'avatar' => $url));
         }
     } else {
     }
     return $url;
 }