当前位置: 首页>>代码示例>>PHP>>正文


PHP Storage::putFile方法代码示例

本文整理汇总了PHP中Illuminate\Support\Facades\Storage::putFile方法的典型用法代码示例。如果您正苦于以下问题:PHP Storage::putFile方法的具体用法?PHP Storage::putFile怎么用?PHP Storage::putFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Illuminate\Support\Facades\Storage的用法示例。


在下文中一共展示了Storage::putFile方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: postUpdateProfile

 /**
  * This method update and save all the changes into the profile's user
  * and return to the user's profile page
  * @param Request $request
  * @return $this|\Illuminate\Http\RedirectResponse
  */
 public function postUpdateProfile(Request $request)
 {
     $validator = Validator::make($request->only(['name']), ['name' => 'required']);
     if ($validator->fails()) {
         return back()->withInput()->withErrors($validator);
     }
     //Find the user if exist before update
     $user = User::findOrFail(Auth::user()->id);
     $user->categories()->detach();
     if ($request->input('categories') && is_array($request->input('categories'))) {
         $user->categories()->attach($request->input('categories'));
     }
     //dd($request->all());
     try {
         //If has file
         if ($request->hasFile('profilePicture') && $request->file('profilePicture')->isValid()) {
             //validate if the uploaded file is an image
             $validator = Validator::make($request->only(['profilePicture']), ['profilePicture' => 'image']);
             if ($validator->fails()) {
                 return back()->withInput()->withErrors($validator);
             }
             //save temp file
             $filename = Storage::putFile('public/profiles', Input::file('profilePicture'));
             //resize to 200px
             $image = Image::make(storage_path() . '/app/' . $filename)->orientate();
             $image = $image->fit(200);
             //delete the temp file
             ImageController::delete($filename);
             //save the new user file
             $filename = str_random(10) . '.jpg';
             ImageController::save('/profiles/' . $filename, $image->stream('jpg', 70));
             //Delete the old image
             if ($user->profileImage && ImageController::exist('profiles/' . $user->profileImage)) {
                 ImageController::delete('profiles/' . $user->profileImage);
             }
         }
     } catch (\Exception $error) {
         Log::error($error->getMessage());
         return back()->withInput()->withErrors(array('message' => trans('app.Error505')));
     }
     //Save the user data
     $user->name = $request->input('name', $user->name);
     $user->aboutMe = $request->input('aboutMe', $user->aboutMe);
     $user->country = $request->input('country', $user->country);
     $user->state = $request->input('state', $user->state);
     $user->city = $request->input('city', $user->city);
     $user->city2 = $request->input('city2', $user->city);
     $user->birthday = empty($request->input('birthday')) ? null : $request->input('birthday');
     $user->profileImage = isset($filename) ? $filename : $user->profileImage;
     $user->save();
     $request->session()->flash('flash-success', trans('app.ProfileSaveSuccess'));
     return redirect()->route('getUserProfile', ['name' => str_slug($user->name), 'id' => $user->id]);
 }
开发者ID:jarriaga,项目名称:cuandomepagas.com,代码行数:59,代码来源:UserProfileController.php


注:本文中的Illuminate\Support\Facades\Storage::putFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。