本文整理汇总了PHP中app\File::uploadFile方法的典型用法代码示例。如果您正苦于以下问题:PHP File::uploadFile方法的具体用法?PHP File::uploadFile怎么用?PHP File::uploadFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\File
的用法示例。
在下文中一共展示了File::uploadFile方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store(Motion $motion, Request $request)
{
if (!Auth::user()->can('create-motions')) {
abort(401, 'You do not have permission to create a motion');
}
$file = new File();
$file->uploadFile('motion_files', 'file', $request);
if (!$file->save()) {
abort(403, $file->errors);
}
$motionFile = new MotionFile();
$motionFile->motion_id = $motion->id;
$motionFile->file_id = $file->id;
if (!$motionFile->save()) {
abort(403, $motionFile->errors);
}
return $motionFile;
}
示例2: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store(Request $request)
{
$validator = Validator::make(array('image' => Input::file('image')), array('image' => 'image'));
if ($validator->fails()) {
abort(403, 'file is not an image');
}
$file = new File();
$file->uploadFile('background_images', 'background_images', $request);
if (!$file->save()) {
abort(403, $file->errors);
}
$backgroundImage = (new BackgroundImage())->secureFill($request->all());
$backgroundImage->user_id = Auth::user()->id;
$backgroundImage->file_id = $file->id;
if (!$backgroundImage->save()) {
abort(403, $backgroundImage->errors);
}
return $backgroundImage;
}
示例3: update
/**
* Can't update most of the fields once they have been verified, only email/password/pubilc.
*
* @param User $user
* @return Response
*/
public function update(User $user, Request $request)
{
if ($user->id != Auth::user()->id && !Auth::user()->can('administrate-users')) {
abort(401, 'You do not have permission to edit this user');
}
//If the user has the authentication level, they can change some things
$user->secureFill($request->except('token'));
if (!$user->save()) {
//Validation failed
abort(400, $user->errors);
}
if ($request->file('government_identification')) {
$file = new File();
$file->uploadFile('government_identification', 'government_identification', $request);
if (!$file->save()) {
abort(403, $file->errors);
}
$user->government_identification_id = $file->id;
}
if ($request->file('avatar')) {
$file = new File();
$file->uploadFile('avatars', 'avatar', $request);
if (!$file->save()) {
abort(403, $file->errors);
}
$user->government_identification_id = $file->id;
}
$user->save();
return $user;
}