本文整理汇总了PHP中Request::file方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::file方法的具体用法?PHP Request::file怎么用?PHP Request::file使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Request
的用法示例。
在下文中一共展示了Request::file方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: record
public function record()
{
if (\Request::hasFile('image') && \Request::file('image')->isValid() && \Auth::user()->suspend == false) {
$file = \Request::file('image');
$input = \Request::all();
$date = new \DateTime();
if (isset($input['anon'])) {
$name = 'anon';
} else {
$name = \Auth::user()->name;
}
$validator = \Validator::make(array('image' => $file, 'category' => $input['category'], 'title' => $input['title'], 'caption' => $input['caption']), array('image' => 'required|max:1200|mimes:jpeg,jpg,gif', 'category' => 'required', 'title' => 'required|max:120', 'caption' => 'required|max:360'));
if ($validator->fails()) {
return redirect('/publish')->withErrors($validator);
} else {
$unique = str_random(10);
$fileName = $unique;
$destinationPath = 'database/pictures/stream_' . $input['category'] . '/';
\Request::file('image')->move($destinationPath, $fileName);
\DB::insert('insert into public.moderation (p_cat, p_ouser, p_title, p_caption, p_imgurl, p_status, p_reported, p_rating, created_at, updated_at) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', [$input['category'], $name, $input['title'], $input['caption'], $unique, 'available', 0, 0, $date, $date]);
$messages = 'Your content has been succesfully submitted. Going on moderation process.';
return redirect('/system/notification')->with('messages', $messages);
}
} else {
$messages = 'Your content data is invalid. The process is aborted.';
return redirect('/system/notification')->with('messages', $messages);
}
}
示例2: upload
public static function upload(Request $request, $tipo, $registroTabela)
{
// A VARIÁVEL $nomeTipo CONTÉM O NOME DO TIPO DA MIDIA E SERÁ USADA COMO NOME DA PASTA DENTRO DA PASTA UPLOADS
$nomeTipo = TipoMidia::findOrFail($tipo)->descricao;
// CRIANDO O REGISTRO PAI NA TABELA MIDIA
$midia = new Midia();
$midia->id_tipo_midia = $tipo;
$midia->id_registro_tabela = $registroTabela;
$midia->descricao = $nomeTipo . ' criado automaticamente com o banner';
$midia->save();
// FAZENDO O UPLOAD E GRAVANDO NA TABELA MULTIMIDIA
#foreach ($request-> as $img) :
// VERIFICANDO SE O ARQUIVO NÃO ESTÁ CORROMPIDO
if ($request->hasFile('imagens')) {
// PEGANDO O NOME ORIGINAL DO ARQUIVO A SER UPADO
$nomeOriginal = $request->file('imagem')->getClientOriginalName();
// MONTANDO O NOVO NOME COM MD5 + IDUNICO BASEADO NO NOME ORIGINAL E CONCATENANDO COM A EXTENÇÃO DO ARQUIVO
$novoNome = md5(uniqid($nomeOriginal)) . '.' . $request->file('imagem')->getClientOriginalExtension();
// MOVENDO O ARQUIVO PARA A PASTA UPLOADS/"TIPO DA MIDIA"
$request->file('imagem')->move('uploads/' . $nomeTipo, $novoNome);
// GRAVANDO NA TABELA MULTIMIDIA
$imagem = new Multimidia();
// PREPARANDO DADOS PARA GRAVAR NA TABELA MULTIMIDIA
$imagem->id_midia = $midia->id_midia;
$imagem->imagem = $novoNome or '';
$imagem->descricao = $request->descricao or '';
$imagem->link = $request->link or '';
$imagem->ordem = $request->ordem or '';
$imagem->video = $request->video or '';
$imagem->save();
}
#endforeach;
}
示例3: 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();
}
示例4: convertir
public function convertir()
{
$fileName = \Request::file('file');
$importador = new ImportadorProyecto($fileName);
$importador->convertir();
return redirect()->action('ImportarProyectoController@show');
}
示例5: upload
public function upload(Request $request)
{
$file = array('photo' => $request->file('photo'));
$rules = array('photo' => 'required');
$validator = \Validator::make($file, $rules);
if ($validator->fails()) {
return \Response::json(array('success' => false));
} else {
// checking file is valid.
if (\Request::file('photo')->isValid()) {
$destinationPath = 'resources/images/userpics';
// upload path
$extension = \Request::file('photo')->getClientOriginalExtension();
// getting image extension
$fileName = rand(11111, 99999) . '.' . $extension;
// renameing image
\Request::file('photo')->move($destinationPath, $fileName);
//updateing Contact record in database //Decided not to do this here. Will send back the filename
//and update the record on client side and then send back to save. This way the picture gets updated
//on form without having to reoad the whole store.
// $contact = Contact::find($request->get('contact_id'));
// $contact->picturefile = $fileName;
// $contact->save();
return \Response::json(array('success' => true, 'filename' => $fileName));
} else {
return \Response::json(array('success' => false));
}
}
}
示例6: savePost
public function savePost()
{
$post = ['title' => Input::get('title'), 'content' => Input::get('content'), 'picture' => Input::get('picture')];
$rules = ['title' => 'required', 'content' => 'required'];
$valid = Validator::make($post, $rules);
if ($valid->passes()) {
$post = new Post($post);
$post->comment_count = 0;
$post->read_more = strlen($post->content) > 120 ? substr($post->content, 0, 120) : $post->content;
/*
$destinationPath = 'uploads'; // upload path
//$extension = Input::file('image')->getClientOriginalExtension(); // getting image extension
$fileName = time(); // renameing image
Input::file('images')->make($destinationPath, $fileName); // uploading file to given path
$post->images = Input::get($fileName);
$pic = Input::file('picture');
$pic_name = time();
Image::make($pic)->save(public_path().'/images/300x'.$pic_name);
$post->images = '/images/'.'300x'.$pic_name;
$post->images = Input::get($pic_name);
*/
$file = Request::file('picture');
$extension = $file;
Images::disk('local')->put($file->getFilename() . '.' . $extension, File::get($file));
$post->images = $file->time();
$post->save();
return Redirect::to('admin/dash-board')->with('success', 'Post is saved!');
} else {
return Redirect::back()->withErrors($valid)->withInput();
}
}
示例7: editRecord
public function editRecord()
{
$name = \Auth::user()->name;
if (\Request::hasFile('avatar') && \Request::file('avatar')->isValid()) {
$file = \Request::file('avatar');
$input = \Request::all();
$validator = \Validator::make(array('avatar' => $file, 'bio' => $input['bio']), array('avatar' => 'max:800|mimes:jpeg,jpg,gif', 'bio' => 'max:1000'));
if ($validator->fails()) {
return redirect('/profile/edit')->withErrors($validator);
} else {
if ($input['avatar_path'] == '0') {
$unique = str_random(20);
$fileName = $unique;
} else {
$fileName = $input['avatar_path'];
}
$destinationPath = 'database/pictures/avatars/';
\Request::file('avatar')->move($destinationPath, $fileName);
\DB::table('users_data')->where('name', $name)->update(['bio' => $input['bio'], 'avatar' => $fileName]);
return redirect('/profile/' . $name);
}
} else {
$input = \Request::all();
$validator = \Validator::make(array('bio' => $input['bio']), array('bio' => 'max:1000'));
if ($validator->fails()) {
return redirect('/profile/edit')->withErrors($validator);
} else {
\DB::table('users_data')->where('name', $name)->update(['bio' => $input['bio']]);
return redirect('/profile/' . $name);
}
}
}
示例8: actualizar
public function actualizar($id, Request $request)
{
try {
$rules = array('nombre' => array('required', 'string', 'min:5', 'unique:promociones,nombre' . $id), 'descripcion' => array('required', 'string', 'min:30'), 'imagen' => array('image', 'image_size:>=300,>=300'), 'inicio' => array('date'), 'fin' => array('date', 'after: inicio'));
$this->validate($request, $rules);
$registro = Promociones::find($id);
$registro->nombre = \Input::get('nombre');
$registro->descripcion = \Input::get('descripcion');
if ($archivo = BRequest::file('foto')) {
$foto = BRequest::file('imagen');
$extension = $foto->getClientOriginalExtension();
Storage::disk('image')->put($foto->getFilename() . '.' . $extension, File::get($foto));
$registro->imagen = $foto->getFilename() . '.' . $extension;
}
if ($inicio = \Input::get('inicio')) {
$registro->inicio = \Input::get('inicio');
}
if ($inicio = \Input::get('fin')) {
$registro->fin = \Input::get('fin');
}
$registro->save();
return \Redirect::route('adminPromociones')->with('alerta', 'La promocion ha sido modificada con exito!');
} catch (ValidationException $e) {
return \Redirect::action('PromocionesCtrl@editar', array('id' => $id))->withInput()->withErrors($e->get_errors());
}
}
示例9: registerRoutes
public static function registerRoutes()
{
Route::post('upload/' . static::$route, ['as' => 'admin.upload.' . static::$route, function () {
$validator = Validator::make(\Request::all(), static::uploadValidationRules());
if ($validator->fails()) {
return Response::make($validator->errors()->get('file'), 400);
}
$file = \Request::file('file');
$upload_path = config('admin.filemanagerDirectory') . \Request::input('path');
$orginalFilename = str_slug(pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME));
$filename = $orginalFilename . '.' . $file->getClientOriginalExtension();
$fullpath = public_path($upload_path);
if (!\File::isDirectory($fullpath)) {
\File::makeDirectory($fullpath, 0755, true);
}
if ($oldFilename = \Request::input('filename')) {
\File::delete($oldFilename);
}
if (\File::exists($fullpath . '/' . $filename)) {
$filename = str_slug($orginalFilename . '-' . time()) . '.' . $file->getClientOriginalExtension();
}
$filepath = $upload_path . '/' . $filename;
$file->move($fullpath, $filename);
return ['url' => asset($filepath), 'value' => $filepath];
}]);
Route::post('upload/delete/' . static::$route, ['as' => 'admin.upload.delete.' . static::$route, function () {
if ($filename = \Request::input('filename')) {
\File::delete($filename);
return "Success";
}
return null;
}]);
}
示例10: addDeliverable
public function addDeliverable(Request $request)
{
$messages = ['not_in' => "You have to choose a client.", 'url' => "Your url must be in the form http://domain.com"];
$this->validate($request, ['deliverable_name' => 'required|max:25', 'client_id' => 'not_in:0', 'deliverable_url' => 'url'], $messages);
$deliverable = new \p4\Deliverable();
$user = \Auth::user();
$client = \p4\Client::find($request->client_id);
$file = \Request::file('deliverable_file');
if ($file) {
$extension = $file->getClientOriginalExtension();
$filename = $file->getClientOriginalName();
$file->move(public_path() . '/uploads/', $filename);
$location = '/uploads/' . $filename;
$deliverable->attachment = $location;
}
$deliverable->url = \Request::get('deliverable_url');
$deliverable->name = \Request::get('deliverable_name');
$deliverable->created_by = $user->id;
$deliverable->date_delivered = Date('Y-m-d H:i:s');
$deliverable->client_id = \Request::get('client_id');
$deliverable->status = \Request::get('status');
$deliverable->client()->associate($client);
$deliverable->save();
$data = array('client' => $client, 'deliverable' => $deliverable);
/**sends email confirmation to client after deliverable is added**/
\Mail::send('emails.deliverable-available', $data, function ($message) use($client, $deliverable) {
$recepient_email = $client->email;
$recepient_name = $client->name;
$subject = 'Your deliverable is now ready for you to review';
$message->to($recepient_email, $recepient_name)->subject($subject);
});
\Session::flash('message', 'Your Deliverable Has Been Uploaded');
return redirect()->back();
}
示例11: uploadImage
/**
* Upload profile image
*/
public function uploadImage($request, $model)
{
if (\Request::file('upl')) {
$image = ImageUploadFacade::attachmentUpload($request->file('upl'), new ProfileAttachment(), 'profile');
$this->updateProfile(['attachment_id' => $image->id], $model);
return $image;
}
}
示例12: uploadOneImage
function uploadOneImage(Request $request, $imageName, $thumb = [])
{
$uploadPath = config('shop.UPLOAD_ROOT_PATH');
$ext = config('shop.UPLOAD_ALLOW_EXT');
//取出php.ini里面允许上传单个文件的大小配置
$upload_max_filesize = (int) ini_get('upload_max_filesize');
//取出配置的上传文件的大小与php.ini中的比较取最小值
$upload_file_size = (int) config('shop.UPLOAD_FILE_SIZE');
$upload_max_size = min($upload_max_filesize, $upload_file_size);
$result = array();
//文件类型
$mime = $request->file($imageName)->getClientMimeType();
if (!in_array($mime, $ext)) {
$result['status'] = 0;
$result['info'] = '文件类型错误,只能上传图片';
return $result;
}
//文件大小
$max_size = $upload_max_size * 1024 * 1024;
$size = $request->file($imageName)->getClientSize();
if ($size > $max_size) {
$result['status'] = 0;
$result['info'] = '文件大小不能超过' . $max_size;
return $result;
}
//上传文件夹,如果不存在,建立文件夹
$date = date("Y_m_d");
$path = $uploadPath . $date;
if (!is_dir($path)) {
mkdir($path, 0777, true);
}
//生成新文件名
//取得之前文件的扩展名
$extension = $request->file($imageName)->getClientOriginalExtension();
$file_name = date("Ymd_His") . '_' . rand(10000, 99999) . '.' . $extension;
$request->file($imageName)->move($path, $file_name);
$img = [];
//原图路径
$img[0] = $uploadPath . $date . '/' . $file_name;
//生成缩略图
if ($thumb) {
foreach ($thumb as $k => $v) {
//打开原图
$goods_ori = Image::make($path . '/' . $img[0]);
//定义生成缩略图的保存路径(名字)
$thumbname = $uploadPath . $date . '/' . $k . '_thumb_' . $file_name;
$goods_ori->resize($v[0], $v[1])->save($thumbname);
//将缩略图的路径放入img数组中用于返回
$img[] = $thumbname;
}
}
//返回新文件名
$result['status'] = 1;
$result['info'] = $img;
return $result;
}
示例13: file
/**
* Get F parms
*
* @param string $key
* @param mixed $default
* @return Request_Parms
*/
public static function file($key = null, $default = null)
{
if ($key) {
return self::file()->{$key} ? self::file()->{$key} : $default;
}
if (!self::$file) {
self::$file = new Request_Multipart($_FILES);
}
return self::$file;
}
示例14: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store()
{
$s3 = AWS::get('s3');
$s3Bucket = 'buildbrighton-bbms';
if (Request::hasFile('image')) {
$file = Request::file('image');
$event = Request::get('textevent');
$time = Request::get('time');
$fileData = Image::make($file)->encode('jpg', 80);
$date = Carbon::createFromFormat('YmdHis', $event);
$folderName = $date->hour . ':' . $date->minute . ':' . $date->second;
try {
$newFilename = \App::environment() . '/cctv/' . $date->year . '/' . $date->month . '/' . $date->day . '/' . $folderName . '/' . $time . '.jpg';
$s3->putObject(array('Bucket' => $s3Bucket, 'Key' => $newFilename, 'Body' => $fileData, 'ACL' => 'public-read', 'ContentType' => 'image/jpg', 'ServerSideEncryption' => 'AES256'));
} catch (\Exception $e) {
\Log::exception($e);
}
//Log::debug('Image saved :https://s3-eu-west-1.amazonaws.com/buildbrighton-bbms/'.$newFilename);
}
if (Request::get('eventend') == 'true') {
$event = Request::get('textevent');
$date = Carbon::createFromFormat('YmdHis', $event);
$folderName = $date->hour . ':' . $date->minute . ':' . $date->second;
$iterator = $s3->getIterator('ListObjects', array('Bucket' => $s3Bucket, 'Prefix' => \App::environment() . '/cctv/' . $date->year . '/' . $date->month . '/' . $date->day . '/' . $folderName));
$images = [];
$imageDurations = [];
foreach ($iterator as $object) {
$images[] = 'https://s3-eu-west-1.amazonaws.com/buildbrighton-bbms/' . $object['Key'];
$imageDurations[] = 35;
}
if (count($images) <= 2) {
//only two images, probably two bad frames
//delete them
foreach ($iterator as $object) {
Log::debug("Deleting small event image " . $object['Key']);
$s3->deleteObject(['Bucket' => $s3Bucket, 'Key' => $object['Key']]);
}
return;
}
$gc = new GifCreator();
$gc->create($images, $imageDurations, 0);
$gifBinary = $gc->getGif();
//Delete the individual frames now we have the gif
foreach ($iterator as $object) {
//Log::debug("Processed gif, deleting frame, ".$object['Key']);
$s3->deleteObject(['Bucket' => $s3Bucket, 'Key' => $object['Key']]);
}
//Save the gif
$newFilename = \App::environment() . '/cctv/' . $date->year . '/' . $date->month . '/' . $date->day . '/' . $folderName . '.gif';
$s3->putObject(array('Bucket' => $s3Bucket, 'Key' => $newFilename, 'Body' => $gifBinary, 'ACL' => 'public-read', 'ContentType' => 'image/gif', 'ServerSideEncryption' => 'AES256'));
//Log::debug('Event Gif generated :https://s3-eu-west-1.amazonaws.com/buildbrighton-bbms/'.$newFilename);
\Slack::to("#cctv")->attach(['image_url' => 'https://s3-eu-west-1.amazonaws.com/buildbrighton-bbms/' . $newFilename, 'color' => 'warning'])->send('Movement detected');
}
}
示例15: store
public function store(Song $songs)
{
$songs->title = \Request::get('title');
$songs->lyrics = \Request::get('lyrics');
$songs->slug = \Request::get('slug');
$songs->save();
$file = \Request::file('myname');
$imageName = $songs->slug . '.' . $file->getClientOriginalExtension();
\Request::file('myname')->move(base_path() . '/public/images/catalog/', $imageName);
return Redirect('songs');
}