本文整理汇总了PHP中Illuminate\Support\Facades\Request::file方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::file方法的具体用法?PHP Request::file怎么用?PHP Request::file使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Support\Facades\Request
的用法示例。
在下文中一共展示了Request::file方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: store
/**
* Upload the file and store
* the file path in the DB.
*/
public function store()
{
// Rules
$rules = array('name' => 'required', 'file' => 'required|max:20000');
$messages = array('max' => 'Please make sure the file size is not larger then 20MB');
// Create validation
$validator = Validator::make(Input::all(), $rules, $messages);
if ($validator->fails()) {
return Redirect::back()->withErrors($validator)->withInput();
}
$directory = "uploads/files/";
// Before anything let's make sure a file was uploaded
if (Input::hasFile('file') && Request::file('file')->isValid()) {
$current_file = Input::file('file');
$filename = Auth::id() . '_' . $current_file->getClientOriginalName();
$current_file->move($directory, $filename);
$file = new Upload();
$file->user_id = Auth::id();
$file->project_id = Input::get('project_id');
$file->name = Input::get('name');
$file->path = $directory . $filename;
$file->save();
return Redirect::back();
}
$upload = new Upload();
$upload->user_id = Auth::id();
$upload->project_id = Input::get('project_id');
$upload->name = Input::get('name');
$upload->path = $directory . $filename;
$upload->save();
return Redirect::back();
}
示例2: getExceptionData
private function getExceptionData($exception)
{
$data = [];
$data['host'] = Request::server('HTTP_HOST');
$data['method'] = Request::method();
$data['fullUrl'] = Request::fullUrl();
if (php_sapi_name() === 'cli') {
$data['host'] = parse_url(config('app.url'), PHP_URL_HOST);
$data['method'] = 'CLI';
}
$data['exception'] = $exception->getMessage();
$data['error'] = $exception->getTraceAsString();
$data['line'] = $exception->getLine();
$data['file'] = $exception->getFile();
$data['class'] = get_class($exception);
$data['storage'] = array('SERVER' => Request::server(), 'GET' => Request::query(), 'POST' => $_POST, 'FILE' => Request::file(), 'OLD' => Request::hasSession() ? Request::old() : [], 'COOKIE' => Request::cookie(), 'SESSION' => Request::hasSession() ? Session::all() : [], 'HEADERS' => Request::header());
$data['storage'] = array_filter($data['storage']);
$count = $this->config['count'];
$data['exegutor'] = [];
$data['file_lines'] = [];
$file = new SplFileObject($data['file']);
for ($i = -1 * abs($count); $i <= abs($count); $i++) {
list($line, $exegutorLine) = $this->getLineInfo($file, $data['line'], $i);
$data['exegutor'][] = $exegutorLine;
$data['file_lines'][$data['line'] + $i] = $line;
}
// to make Symfony exception more readable
if ($data['class'] == 'Symfony\\Component\\Debug\\Exception\\FatalErrorException') {
preg_match("~^(.+)' in ~", $data['exception'], $matches);
if (isset($matches[1])) {
$data['exception'] = $matches[1];
}
}
return $data;
}
示例3: sendMail
public function sendMail()
{
$dets = array('msg' => Request::input('mailDets'), 'subject' => Request::input('subjectH'), 'to' => Request::input('toH'), 'file' => Request::file('file'));
$rules = array('msg' => 'required', 'subject' => 'required', 'to' => 'required|email');
$messages = array('msg.required' => 'The email body is required', 'to.required' => 'The recipient\'s address is required', 'to.email' => 'The recepient address is not of the correct format');
$validator = Validator::make($dets, $rules, $messages);
if ($validator->fails()) {
// send back to the page with the input data and errors
return Redirect::back()->withInput()->withErrors($validator);
} else {
//Get the details from the form and send it as an array to the function.
try {
Mail::send(array(), array(), function ($message) use($dets) {
$message->from('paintbuddyProj@gmail.com', 'PaintBuddy Team');
$message->to($dets['to']);
$message->subject($dets['subject']);
$message->setBody($dets['msg'], 'text/html');
if (isset($dets['file'])) {
$message->attach(Request::file('file'), ['as' => Request::file('file')->getClientOriginalName(), 'mime' => Request::file('file')->getClientOriginalExtension()]);
}
});
} catch (\Exception $e) {
throw new SendMailException($e->getMessage());
}
if (count(Mail::failures()) > 0) {
return Redirect::back()->withInput()->withErrors('Mail was not sucessfully sent. Please try again');
} else {
return Redirect::back()->with('success', true)->with('message', 'Mail sucessfully sent');
}
}
}
示例4: addItems
/**
* Add items to the database and the images to 'img/tempEng' directory.
*
* @author Sinthujan G.
* @return mixed Redirects to view with Success or Error messages.
*/
public function addItems()
{
$dets = array('catName' => Request::input('cat_Name'), 'image' => Request::file('image'), 'name' => Request::input('iName'), 'description' => Request::input('iDescrip'), 'size' => Request::input('iSize'), 'price' => Request::input('iPrice'));
//setting up rules
$rules = array('image' => 'required|mimes:jpeg,bmp,png', 'name' => 'required', 'description' => 'required', 'size' => 'required', 'price' => 'required|numeric');
// doing the validation, passing post data, rules and the messages
$validator = Validator::make($dets, $rules);
if ($validator->fails()) {
// send back to the page with the input data and errors
return Redirect::to('aitem')->withInput()->withErrors($validator);
} else {
// checking file is valid.
if (Request::file('image')->isValid()) {
$destinationPath = 'img/tempEng';
$extension = Request::file('image')->getClientOriginalExtension();
$fileName = rand(11111, 99999) . Carbon::now()->format('Y-m-d') . '.' . $extension;
Request::file('image')->move($destinationPath, $fileName);
$res = DB::table('items')->insertGetId(['itName' => $dets['name'], 'itDescrip' => $dets['description'], 'imName' => $fileName, 'itSize' => $dets['size'], 'catRef' => $dets['catName'], 'price' => $dets['price'], 'status' => 'AC']);
if (!$res) {
App::abort(500, 'Some Error');
}
return Redirect::to('aitem')->with('success', true)->with('message', 'Item successfully added');
} else {
// sending back with error message.
Session::flash('error', 'uploaded file is not valid');
App::abort(500, 'Error');
}
}
}
示例5: store
/**
* Update an existing model.
*
* @param array Data to update a model
*
* @return bool
*/
public function store(array $data)
{
if (!empty($data['image']) && $data['image'] == 'delete') {
$data['image'] = null;
}
if (Request::hasFile('image')) {
$file = FileUpload::handle(Request::file('image'), 'uploads/settings');
$data['image'] = $file['filename'];
}
foreach ($data as $group_name => $array) {
if (!is_array($array)) {
$array = [$group_name => $array];
$group_name = 'config';
}
foreach ($array as $key_name => $value) {
$model = $this->model->where('key_name', $key_name)->where('group_name', $group_name)->first();
$model = $model ? $model : new $this->model();
$model->group_name = $group_name;
$model->key_name = $key_name;
$model->value = $value;
$model->save();
}
}
return true;
}
示例6: saveImages
/**
* Save Image.
*/
public function saveImages()
{
$imageFields = $this->getImageFields();
$currentUploadDir = $this->getCurrentUploadDir();
foreach ($imageFields as $imageFieldName => $options) {
if (array_get($this->attributes, $imageFieldName) instanceof UploadedFile) {
$file = Request::file($imageFieldName);
$filename = $file->getClientOriginalName();
$file->move($this->getThumbnailPath('original'), $filename);
foreach ($options['thumbnails'] as $thumbnailName => $thumbnailOptions) {
$image = Image::make($this->getThumbnailPath('original') . $filename);
$resizeType = array_get($thumbnailOptions, 'type', 'crop');
switch ($resizeType) {
case 'crop':
$image->fit($thumbnailOptions['width'], $thumbnailOptions['height']);
break;
case 'resize':
$image->resize($thumbnailOptions['width'], $thumbnailOptions['height'], function ($constraint) {
$constraint->aspectRatio();
});
break;
}
$thumbnailPath = $this->getThumbnailPath($thumbnailName);
if (!File::isDirectory($thumbnailPath)) {
File::makeDirectory($thumbnailPath);
}
$image->save($thumbnailPath . $filename);
}
$this->attributes[$imageFieldName] = $filename;
} elseif ($this->original) {
$this->attributes[$imageFieldName] = $this->original[$imageFieldName];
}
}
}
示例7: saveFile
/**
* Saves File.
*
* @param string $fileName File input name
* @param string $location Storage location
*
* @return array
*/
public static function saveFile($fileName, $directory = '', $fileTypes = [])
{
if (is_object($fileName)) {
$file = $fileName;
$originalName = $file->getClientOriginalName();
} else {
$file = Request::file($fileName);
$originalName = false;
}
if (is_null($file)) {
return false;
}
if (File::size($file) > Config::get('quarx.maxFileUploadSize', '')) {
throw new Exception('This file is too large', 1);
}
if (substr($directory, 0, -1) != '/') {
$directory .= '/';
}
$extension = $file->getClientOriginalExtension();
$newFileName = md5(rand(1111, 9999) . time());
// In case we don't want that file type
if (!empty($fileTypes)) {
if (!in_array($extension, $fileTypes)) {
throw new Exception('Incorrect file type', 1);
}
}
Storage::disk(Config::get('quarx.storage-location', 'local'))->put($directory . $newFileName . '.' . $extension, File::get($file));
return ['original' => $originalName ?: $file->getFilename() . '.' . $extension, 'name' => $directory . $newFileName . '.' . $extension];
}
示例8: create
public function create(Request $request)
{
$file = Request::file('file');
$randomFilename = str_random();
$return['fullsize'] = $this->makeImage($file, 1920, 1080, $randomFilename);
$return['thumbnail'] = $this->makeImage($file, 200, 200, $randomFilename, $return['fullsize']);
return $return;
}
示例9: upload
public function upload()
{
if (! Request::hasFile($this->fileFiled)) {
throw new FileUploadException(100001, '没有该文件');
}
$file = Request::file($this->fileFiled);
if (! $file->isValid()) {
throw new FileUploadException(100002, '文件上传失败');
}
// 获取信息
$originalName = $file->getClientOriginalName();
$mimeType = $file->getClientMimeType();
$fileSize = $file->getClientSize();
$extension = strtolower($file->getClientOriginalExtension());
// 判断后缀
if (isset($this->config['extensions'])) {
if (! in_array($extension, $this->config['extensions'])) {
throw new FileUploadException(100003, '不支持的文件类型');
}
}
// 判断大小
if (isset($this->config['maxSize'])) {
if ($fileSize > $this->config['maxSize']) {
throw new FileUploadExceptions(100004, '文件大小超过最大上传限制');
}
}
// 创建目录结构
$sub = isset($this->config['subDir']) ? '/' . trim(date($this->config['subDir'], time()), "/\\") . '/' : '/';
$dir = trim($this->config['rootDir'], "/\\") . $sub;
// 文件名
if (isset($this->config['filename'])) {
$filename = $this->config['filename'];
} else {
$filename = time() . str_random(10) . '.' . $extension;
}
$file->move($dir, $filename);
if ($file->getError() != 0) {
throw new FileUploadException(100005, '移动文件失败');
}
return [
'originalName' => $originalName,
'filename' => $filename,
'path' => $dir . $filename,
'fileSize' => $fileSize,
'mimeType' => $mimeType,
];
}
示例10: image
public function image($image, $image_name, $path, $width, $height)
{
$name_of_image = $image_name . '.' . Request::file($image)->getClientOriginalExtension();
Request::file($image)->move(base_path() . $path, $name_of_image);
$img = Image::make(base_path() . $path . $name_of_image);
$img->resize($width, $height, function ($constraint) {
$constraint->aspectRatio();
});
return $name_of_image;
}
示例11: upload
public function upload($name)
{
// Verifying the file
if (!Request::hasFile($name) || !Request::file($name)->isValid()) {
return false;
}
$this->file = Request::file($name);
// $this->filesystem->put('docs/file_12_thumb.txt', 'file contents', ['visibility' => 'private']);
var_dump($this->filesystem->has('docs/file_12_thumb.txt'));
// var_dump($this->filesystem->delete('docs/file_12_thumb.txt'));
}
示例12: image
/**
* handle image upload route
*/
public function image()
{
if (Request::hasFile('image') && Request::has('table_name') && Request::has('field_name')) {
return json_encode(self::saveImage(Request::input('table_name'), Request::input('field_name'), Request::file('image'), null, Request::file('image')->getClientOriginalExtension()));
} elseif (!Request::hasFile('image')) {
return 'no image';
} elseif (!Request::hasFile('table_name')) {
return 'no table_name';
} elseif (!Request::hasFile('field_name')) {
return 'no field_name';
}
}
示例13: saveFiles
/**
* Save file method.
*/
public function saveFiles()
{
$fileFields = $this->getFileFields();
foreach ($fileFields as $fieldName => $options) {
$file = Request::file($fieldName);
if ($file instanceof UploadedFile && $file->isValid()) {
$filename = $file->getClientOriginalName();
$fileSavePath = $this->getFileSavePath($options['dirName']);
$file->move($fileSavePath, $filename);
$this->attributes[$fieldName] = $fileSavePath . $filename;
}
}
}
示例14: create
public function create(Request $request)
{
$file = Request::file('file');
$randomFilename = str_random();
$fullsizeWidth = Request::input('full_width', null);
$fullsizeHeight = Request::input('full_height', null);
$thumbnailWidth = Request::input('thumb_width', 200);
$thumbnailHeight = Request::input('thumb_height', 200);
$overrideDeduplication = Request::input('override_deduplication', 'false');
$return['fullsize'] = $this->makeImage($file, $fullsizeWidth, $fullsizeHeight, $randomFilename, null, $overrideDeduplication);
$return['thumbnail'] = $this->makeImage($file, $thumbnailWidth, $thumbnailHeight, $randomFilename, $return['fullsize'], $overrideDeduplication);
return $return;
}
示例15: apoyo
public function apoyo(Asignacion $request, $id)
{
$user = Auth::user()->id;
$actividad = $this->search($id);
$file = Request::file('archivo');
$nombre = $file->getClientOriginalName();
$extension = $file->getClientOriginalExtension();
$exists = Storage::disk('local')->exists($nombre);
if (!$exists) {
Storage::disk('local')->put($nombre, File::get($file));
$entry = Apoyo::create(['mime' => $file->getClientMimeType(), 'original_filename' => $file->getClientOriginalName(), 'filename' => $nombre, 'actividad_id' => $id, 'user_id' => $user]);
$entry->save();
}
}