本文整理汇总了PHP中Illuminate\Support\Facades\Request::hasFile方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::hasFile方法的具体用法?PHP Request::hasFile怎么用?PHP Request::hasFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Support\Facades\Request
的用法示例。
在下文中一共展示了Request::hasFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: 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,
];
}
示例3: files
public function files($fields = array())
{
$returns = array();
foreach ($fields as $field) {
if (!Request::hasFile($field) || !Input::file($field)->isValid()) {
throw new \Exception('PHOTO_MISSING_UPLOAD_FILE', PHOTO_MISSING_UPLOAD_FILE);
}
$returns[] = Input::file($field);
}
return $returns;
}
示例4: 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'));
}
示例5: 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';
}
}
示例6: imgUpload
public function imgUpload()
{
//图片最大上传大小
$maxImgSize = 10485760;
//允许上传图片类型
$allowed_extensions = ["png", "jpg"];
if (!Request::hasFile('file_data')) {
return response()->json(['errorCode' => 1, 'msg' => '请选择上传文件']);
}
$file = Request::file('file_data');
if ($file->getError() != 0) {
switch ($file->getError()) {
case 1:
$msg = '上传的文件超过了 php.ini 中 upload_max_filesize 选项限制的值';
break;
case 2:
$msg = '上传文件的大小超过了 HTML 表单中 MAX_FILE_SIZE 选项指定的值';
break;
case 3:
$msg = '文件只有部分被上传';
break;
case 4:
$msg = '没有文件被上传';
break;
case 6:
$msg = '找不到临时文件夹';
break;
default:
$msg = '文件写入失败';
}
return response()->json(['errorCode' => 1, 'msg' => $msg]);
}
$img_suffix = $file->getClientOriginalExtension();
if ($img_suffix && !in_array($img_suffix, $allowed_extensions)) {
return response()->json(['errorCode' => 1, 'msg' => '请选择png、jpg、jpeg后缀的图片']);
}
if ($file->getSize() > $maxImgSize) {
return response()->json(['errorCode' => 1, 'msg' => '请选择小于10M的图片']);
}
$destinationPath = 'uploads/images/';
$date = date('Ymd');
if (!file_exists($destinationPath . $date)) {
mkdir($destinationPath . $date, 0777, true);
}
$savePath = $destinationPath . $date . '/';
$fileName = str_random(15) . '.' . $img_suffix;
$file->move($savePath, $fileName);
return response()->json(['errorCode' => 0, 'path' => $savePath . $fileName]);
}
示例7: postImage
public function postImage(\Prehistorical\ImageFileLogic\ImageFileLogic $ifl)
{
if (Request::hasFile('imagefile') && Request::has('name')) {
//id - это айди элемента группы, картинки принадлежащие непосредственно блоку проходят с адйди=0
if (Request::has('id')) {
$id = Request::input('id');
} else {
$id = 0;
}
$result = $ifl->storeImage(Request::input('name'), $id, Request::file('imagefile'), false);
return $result;
} else {
return ['status' => 'Не хватает параметров (файла или имени сущности) для сохранения.'];
}
}
示例8: postIndex
/**
* @return Response
*/
public function postIndex()
{
if (!Request::hasFile('item_img')) {
$this->export(50000);
die;
}
$destinationPath = base_path() . '/public/assets/uploads';
$fileName = md5(microtime()) . '.' . Request::file('item_img')->getClientOriginalExtension();
$isMoved = Request::file('item_img')->move($destinationPath, $fileName);
if ($isMoved) {
$this->export(200, $fileName);
} else {
$this->export(50000);
}
}
示例9: register
public function register(Request $request)
{
$user = $request->session()->get('user');
$categories = buildingCategory::all();
if (isset($request['buildingName']) && !empty($request['buildingName'])) {
$buildingName = $request['buildingName'];
}
if (isset($request['lattitude']) && !empty($request['lattitude'])) {
$lattitude = $request['lattitude'];
}
if (isset($request['longitude']) && !empty($request['longitude'])) {
$longitude = $request['longitude'];
}
if (isset($request['category']) && !empty($request['category'])) {
$category = $request['category'];
}
if (isset($request['location']) && !empty($request['location'])) {
$location = $request['location'];
}
if (isset($request['desc']) && !empty($request['desc'])) {
$desc = $request['desc'];
}
$uploadMsg = "";
$fileName = '';
if (RequestStatic::hasFile('image') && RequestStatic::file('image')->isValid()) {
$extension = Input::file('image')->getClientOriginalExtension();
// getting image extension
$fileName = rand(11111, 99999) . '.' . $extension;
// renameing image
$name = $this->destinationPath;
RequestStatic::file('image')->move($name, $fileName);
}
// Retrieve user session
$user = $request->session()->get('user');
//Save building for user
$building = new buildingModel();
$building->buildingName = $buildingName;
$building->lattitude = $lattitude;
$building->longitude = $longitude;
$building->buildingLocation = $location;
$building->buildingCatId = $category;
$building->landlordID = $user[0]->ID;
$building->desc = $desc;
$building->image = $fileName;
$building->save();
Session::flash('success', 'Building successfully registered');
return Redirect::to('addBuilding');
}
示例10: register
public function register(Request $request)
{
$user = $request->session()->get('user');
$categories = vehicleCategory::all();
if (isset($request['name']) && !empty($request['name'])) {
$name = $request['name'];
}
if (isset($request['category']) && !empty($request['category'])) {
$category = $request['category'];
}
if (isset($request['models']) && !empty($request['models'])) {
$models = $request['models'];
}
if (isset($request['color']) && !empty($request['color'])) {
$color = $request['color'];
}
if (isset($request['numOfSeats']) && !empty($request['numOfSeats'])) {
$numOfSeats = $request['numOfSeats'];
}
if (isset($request['transmission']) && !empty($request['transmission'])) {
$transmission = $request['transmission'];
}
$uploadMsg = "";
$fileName = '';
if (RequestStatic::hasFile('image') && RequestStatic::file('image')->isValid()) {
$extension = Input::file('image')->getClientOriginalExtension();
// getting image extension
$fileName = rand(11111, 99999) . '.' . $extension;
// renameing image
$name = $this->destinationPath;
RequestStatic::file('image')->move($name, $fileName);
}
// Retrieve user session
$user = $request->session()->get('user');
//Save vehicles for specific user
$vehicle = new vehicleModel();
$vehicle->vehicleOwnerID = $user[0]->id;
$vehicle->vehicleName = $name;
$vehicle->color = $color;
$vehicle->numOfSeats = $numOfSeats;
$vehicle->transmission = $transmission;
$vehicle->image = $fileName;
$vehicle->models = $models;
$vehicle->vehicleCatID = $category;
$vehicle->save();
Session::flash('success', 'vehicle successfully registered');
return Redirect::to('addVehicle');
}
示例11: uploadImgFile
/**
* MDEditor Upload ImgFile
* @param string $path
* @return array
*/
public static function uploadImgFile($path)
{
try {
if (Request::hasFile('editormd-image-file')) {
$pic = Request::file('editormd-image-file');
if ($pic->isValid()) {
$newName = md5(rand(1, 1000) . $pic->getClientOriginalName()) . "." . $pic->getClientOriginalExtension();
$pic->move($path, $newName);
$url = asset($path . '/' . $newName);
} else {
self::addError('The file is invalid');
}
} else {
self::addError('Not File');
}
} catch (\Exception $e) {
self::addError($e->getMessage());
}
$data = array('success' => !empty($message) ? 0 : 1, 'message' => self::getLastError(), 'url' => !empty($url) ? $url : '');
return $data;
}
示例12: saving
/**
* On save, upload files.
*
* @param Model $model eloquent
*
* @return mixed false or void
*/
public function saving(Model $model)
{
if (!($attachments = $model->attachments)) {
return;
}
foreach ($attachments as $fieldname) {
if (Request::hasFile($fieldname)) {
// delete prev image
$file = FileUpload::handle(Request::file($fieldname), 'uploads/' . $model->getTable());
$model->{$fieldname} = $file['filename'];
if ($model->getTable() == 'files') {
$model->fill($file);
}
} else {
if ($model->{$fieldname} == 'delete') {
$model->{$fieldname} = null;
} else {
$model->{$fieldname} = $model->getOriginal($fieldname);
}
}
}
}
示例13: upload
public function upload()
{
if (Request::hasFile('file')) {
$rules = array('file' => 'mimes:png,jpeg,jpg,bmp');
$validator = Validator::make(Request::all(), $rules);
if ($validator->fails()) {
return (new Response(array('status' => false, 'msg' => 'Please choose a picture'), 200))->header('Content-Type', "json");
} else {
$str = "";
try {
$param_picture = Request::input('param_picture');
$id = Request::input('param');
$token = Request::input('token');
$file = Request::file('file');
$filename = "";
$field_update = array();
if ($param_picture == "ava") {
$filename = md5('Avatar -' . date("Y-m-d H:i:s") . '-') . '.' . $file->getClientOriginalExtension();
$field_update = array('users_avatar' => $filename);
} else {
$filename = md5('Cover -' . date("Y-m-d H:i:s") . '-') . '.' . $file->getClientOriginalExtension();
$field_update = array('users_cover' => $filename);
}
$destinationPath = 'UPLOADED';
$file->move($destinationPath, $filename);
$data_find = table_users_detail::find($id);
$data_find->update($field_update);
$str = "success ";
return (new Response(array('status' => true, 'msg' => $str, 'f' => $filename), 200))->header('Content-Type', "json");
} catch (Exception $e) {
$str = $e->getMessage();
return (new Response(array('status' => false, 'msg' => $str), 200))->header('Content-Type', "json");
}
}
} else {
return (new Response(array('status' => false, 'msg' => 'Authentication Failed'), 200))->header('Content-Type', "json");
}
}
示例14: hasFile
/**
* Determine if the uploaded data contains a file.
*
* @param string $key
* @return bool
*/
public function hasFile($key)
{
return parent::hasFile($key);
}
示例15: teacherSave
public function teacherSave()
{
$v = Validator::make(Input::all(), ['id' => 'required|numeric', 'name' => 'required', 'picture' => 'image', 'synopsis' => 'required', 'taxonomy' => 'required', 'description' => 'required']);
if ($v->fails()) {
return View::getBadRequstView($v->messages());
} else {
if (Teacher::find(Input::get('id')) == null) {
return View::getBadRequstView('no teach of this id. id is ' . Input::get('id'));
}
}
$teacher = Teacher::find(Input::get('id'));
$teacher->name = Input::get('name');
$teacher->description = Input::get('description');
$teacher->synopsis = Input::get('synopsis');
$teacher->famous = Input::get('famous', 0);
$teacher->taxonomy = Input::get('taxonomy');
if (Req::hasFile('picture')) {
$filename = $this->getRandFilename();
$teacher->picture = '/uploadimg/' . $filename;
Req::file('picture')->move(storage_path() . '/../public/uploadimg', $filename);
}
$teacher->save();
return redirect('/admin/teacher');
}