本文整理汇总了PHP中App\Http\Requests\Request::file方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::file方法的具体用法?PHP Request::file怎么用?PHP Request::file使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类App\Http\Requests\Request
的用法示例。
在下文中一共展示了Request::file方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: updatePost
/**
* Update post
* @param Request $request
* @param int $id
* @return void
*/
public function updatePost(Request $request, $id)
{
DB::beginTransaction();
try {
$post = Post::findOrFail($id);
$oldImage = "";
$inputs = $request->all();
if ($request->hasFile('images')) {
$oldImage = public_path() . config('model.posts.path_folder_photo_post') . $post->images;
$imageFile = $request->file('images');
$inputs['images'] = $this->__storeImagePost($imageFile);
} else {
unset($inputs['images']);
}
if ($inputs['type'] == 2) {
$this->__changeStickyPost($id);
}
$post->fill($inputs);
$post->save();
if (strlen($oldImage) != 0) {
if (File::exists($oldImage)) {
File::delete($oldImage);
}
}
} catch (Exception $e) {
DB::rollback();
throw new Exception("Error Processing Request", 1);
}
DB::commit();
}
示例2: store
/**
* save document
* @param Request $request
* @return array
*/
public function store(Request $request)
{
try {
$file = $request->file('file');
$extension = $file->getClientOriginalExtension();
if (!in_array($extension, $this->allowedExtensions)) {
return ['status' => 'warning', 'message' => 'No such files allowed.'];
}
$filename = str_replace(' ', '-', preg_replace('/\\s+/', ' ', $file->getClientOriginalName()));
$extension = substr($filename, stripos($filename, '.'));
$filename = sprintf('%s-%s%s', substr($filename, 0, stripos($filename, '.')), date('Ymdhms'), $extension);
$url = url(sprintf('files/documents/%s', $filename));
$document = $this->documentManager->getDocument($this->orgId, $url, $filename);
if ($document->exists) {
return ['status' => 'danger', 'message' => 'Document already exists.'];
}
Storage::put(sprintf('%s/%s', 'documents', $filename), File::get($file));
$this->documentManager->store($document);
} catch (\Exception $e) {
return ['status' => 'danger', 'message' => 'Failed to upload Document. Error: ' . $e->getMessage()];
}
return ['status' => 'success', 'message' => 'Uploaded Successfully.', 'data' => $this->getDocuments()];
}
示例3: storeUserRegister
public function storeUserRegister(Request $request)
{
DB::beginTransaction();
try {
$inputs = $request->all();
if ($request->hasFile('photo')) {
$photoFile = $request->file('photo');
$inputs['photo'] = $this->__storeImageUser($photoFile);
} else {
unset($inputs['photo']);
}
$role = Role::where('slug', 'user')->first();
$inputs['role_id'] = $role->id;
$inputs['register_token'] = str_random(30);
$inputs['password'] = bcrypt($inputs['password']);
$user = User::create($inputs);
$inputs['user_id'] = $user->id;
UserInfo::create($inputs);
} catch (Exception $e) {
DB::rollback();
}
DB::commit();
return $user;
}
示例4: store
/**
* store the uploaded transaction
* @param Request $request
* @param $id
* @param UploadTransactionRequest $uploadTransactionRequest
* @param CsvImportValidator $csvImportValidator
* @return $this
*/
public function store(Request $request, $id, UploadTransactionRequest $uploadTransactionRequest, CsvImportValidator $csvImportValidator)
{
$activity = $this->activityManager->getActivityData($id);
if (Gate::denies('ownership', $activity)) {
return redirect()->back()->withResponse($this->getNoPrivilegesMessage());
}
$this->authorize('add_activity', $activity);
$file = $request->file('transaction');
if ($this->uploadTransactionManager->isEmptyCsv($file)) {
return redirect()->back()->withResponse(['type' => 'danger', 'code' => ['empty_template', ['name' => 'Transaction']]]);
}
$validator = $this->validatorForCurrentCsvType($file, $csvImportValidator);
if (null === $validator) {
return redirect()->back()->withResponse(['type' => 'danger', 'code' => ['header_mismatch', ['name' => 'Transaction']]]);
}
if (null !== $validator && $validator->fails()) {
$response = ['type' => 'danger', 'messages' => $validator->errors()->all()];
return redirect()->back()->withInput()->withResponse($response);
}
$this->uploadTransactionManager->save($file, $activity);
$this->activityManager->resetActivityWorkflow($id);
$response = ['type' => 'success', 'code' => ['updated', ['name' => 'Transactions']]];
return redirect()->to(sprintf('/activity/%s/transaction', $id))->withResponse($response);
}
示例5: store
/**
* Stores the activity by uploading csv
* @param Request $request
* @param UploadActivityRequest $uploadActivityRequest
* @param CsvImportValidator $csvImportValidator
* @param IatiIdentifierRepository $iatiIdentifierRepository
* @return $this
*/
public function store(Request $request, UploadActivityRequest $uploadActivityRequest, CsvImportValidator $csvImportValidator, IatiIdentifierRepository $iatiIdentifierRepository)
{
$organization = $this->organizationManager->getOrganization($this->organizationId);
$this->authorize('add_activity', $organization);
$settings = $this->settingsManager->getSettings($this->organizationId);
$defaultFieldValues = $settings->default_field_values;
$defaultFieldGroups = $settings->default_field_groups;
if (!isset($organization->reporting_org[0])) {
$response = ['type' => 'warning', 'code' => ['settings', ['name' => 'activity']]];
return redirect('/settings')->withResponse($response);
}
$identifiers = [];
$activityIdentifiers = $iatiIdentifierRepository->getIdentifiersForOrganization();
foreach ($activityIdentifiers as $identifier) {
$identifiers[] = $identifier->identifier['activity_identifier'];
}
$file = $request->file('activity');
$uploadedActivityArray = $this->uploadActivityManager->getVersion()->getExcel()->load($file)->toArray();
$geopolitical = $defaultFieldGroups[0]['Geopolitical Information'];
foreach ($uploadedActivityArray as $activity) {
$recipientRegionExist = array_key_exists('recipient_region', $geopolitical);
if (!$recipientRegionExist && !is_null($activity['recipient_region'])) {
return redirect()->back()->withResponse(['type' => 'danger', 'code' => ['recipient_region_unselected_in_settings', ['name' => 'Activity']]]);
}
}
if ($this->uploadActivityManager->isEmptyCsv($file)) {
return redirect()->back()->withResponse(['type' => 'danger', 'code' => ['empty_template', ['name' => 'Activity']]]);
}
$validator = $csvImportValidator->validator->isValidActivityCsv($file, $identifiers);
if (!$validator) {
$response = ['type' => 'danger', 'code' => ['csv_template_error', ['name' => '']]];
return redirect()->back()->withResponse($response);
} elseif ($validator->fails()) {
$failedRows = $validator->failures();
$uploadedActivities = $this->uploadActivityManager->getVersion()->getExcel()->load($file)->toArray();
$validActivities = array_keys(array_diff_key($uploadedActivities, $failedRows));
$validActivityIndices = [];
foreach ($validActivities as $validActivity) {
$validActivityIndices[] = $validActivity + 1;
}
$filename = 'temporary-' . $this->organizationId . 'activity';
$this->temporarilyStoreCsvFor($validActivities, $filename);
$validCsvFilePath = storage_path() . '/exports/' . $filename . '.csv';
if (!$this->saveValidatedActivities($validCsvFilePath, $defaultFieldValues)) {
return redirect()->back()->withResponse(['type' => 'warning', 'code' => ['save_failed', ['name' => 'Activity']]]);
}
return $this->invalidActivities($validator, $validActivityIndices, $failedRows);
}
$check = $this->uploadActivityManager->save($file, $organization, $defaultFieldValues);
if (is_a($check, 'Illuminate\\View\\View')) {
return $check;
}
$response = $check ? ['type' => 'success', 'code' => ['updated', ['name' => 'Activities']]] : ['type' => 'danger', 'code' => ['update_failed', ['name' => 'Activities']]];
return redirect()->to(sprintf('/activity'))->withResponse($response);
}