Input
Input
Please note that both Input and Request do NOT sanitize your data, it is up to you to do that.
Basic Input
You may access all user input with a few simple methods. You do not need to worry about the HTTP verb used for the request, as input is accessed in the same way for all verbs.
Retrieving An Input Value
$name = Input::get('name');
Retrieving A Default Value If The Input Value Is Absent
$name = Input::get('name', 'Sally');
Determining If An Input Value Is Present
if (Input::has('name'))
{
//
}
Getting All Input For The Request
$input = Input::all();
Getting Only Some Of The Request Input
$input = Input::only('username', 'password');
$input = Input::except('credit_card');
When working on forms with "array" inputs, you may use dot notation to access the arrays:
$input = Input::get('products.0.name');
Note: Some JavaScript libraries such as Backbone may send input to the application as JSON. You may access this data via Input::get like normal.
Old Input
You may need to keep input from one request until the next request. For example, you may need to re-populate a form after checking it for validation errors.
Flashing Input To The Session
Input::flash();
Flashing Only Some Input To The Session
Input::flashOnly('username', 'email');
Input::flashExcept('password');
Since you often will want to flash input in association with a redirect to the previous page, you may easily chain input flashing onto a redirect.
return Redirect::to('form')->withInput();
return Redirect::to('form')->withInput(Input::except('password'));
Note: You may flash other data across requests using the Session class.
Retrieving Old Data
Input::old('username');
Files
Retrieving An Uploaded File
$file = Input::file('photo');
Determining If A File Was Uploaded
if (Input::hasFile('photo'))
{
//
}
The object returned by the file method is an instance of the Symfony\Component\HttpFoundation\File\UploadedFile class, which extends the PHP SplFileInfo class and provides a variety of methods for interacting with the file.
Determining If An Uploaded File Is Valid
if (Input::file('photo')->isValid())
{
//
}
Moving An Uploaded File
Input::file('photo')->move($destinationPath);
Input::file('photo')->move($destinationPath, $fileName);
Retrieving The Path To An Uploaded File
$path = Input::file('photo')->getRealPath();
Retrieving The Original Name Of An Uploaded File
$name = Input::file('photo')->getClientOriginalName();
Retrieving The Extension Of An Uploaded File
$extension = Input::file('photo')->getClientOriginalExtension();
Retrieving The Size Of An Uploaded File
$size = Input::file('photo')->getSize();
Retrieving The MIME Type Of An Uploaded File
$mime = Input::file('photo')->getMimeType();
相关文章
- How many types the input element has in Html?
- The input stream is not a valid binary format.
- input屏蔽历史记录 ;function($,undefined) 前面的分号是什么用处 JSON 和 JSONP 两兄弟 document.body.scrollTop与document.documentElement.scrollTop兼容 URL中的# 网站性能优化 前端必知的ajax 简单理解同步与异步 那些年,我们被耍过的bug——has
- 微信小程序 - input 实现双向数据绑定(实时更新数据变化)
- [转]SpringMVC<from:form>表单标签和<input>表单标签简介
- input事件change无法上传相同文件的问题
- vue 组件 模板input双向数据数据
- input 限制上传文件的类型
- 微信小程序 input 的 type属性 text、number、idcard、digit 区别
- html input type="button" 页面跳转
- input标签根据输入字符动态自适应宽度的实现
- HTML5 input file控件使用accept过滤限制的文件类型以及在谷歌下打开很慢的问题
- 移除input在type="number"时的上下箭头