本文整理汇总了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]);
}