當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。