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();

Input的更多相关文章

  1. HTML中上传与读取图片或文件(input file)----在路上(25)

    input file相关知识简例 在此介绍的input file相关知识为: 上传照片及文件,其中包括单次上传.批量上传.删除照片.增加照片.读取图片.对上传的图片或文件的判断,比如限制图片的张数.限 ...

  2. HTML5 input元素新的特性

    在HTML5中,<input>元素增加了许多新的属性.方法及控件.本文章分别对这三方面进行介绍. 目录 1. 属性 2. 方法 3. 新控件 1. 属性 <input>元素在H ...

  3. input[tyle="file"]样式修改及上传文件名显示

    默认的上传样式我们总觉得不太好看,根据需求总想改成和上下结构统一的风格…… 实现方法和思路: 1.在input元素外加a超链接标签 2.给a标签设置按钮样式 3.设置input[type='file' ...

  4. input标签中button在iPhone中圆角的问题

    1.问题 使用H5编写微信页面时,使用<input type="button"/>时,在Android手机中显示正常,但是在iPhone手机中则显示不正常,显示为圆角样 ...

  5. input type='file'上传控件假样式

    采用bootstrap框架样式 <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> &l ...

  6. css3更改input单选和多选的样式

    在项目开发中我们经常会遇到需要更改input单选和多选样式的情况,今天就给大家介绍一种简单改变input单选和多选样式的办法. 在这之前先简单介绍一下:before伪类 :before 选择器向选定的 ...

  7. css样式让input垂直居中

    css样式让input垂直居中 css代码: .div1{ border: 1px solid #CCC; width:1120px; height:40px; margin:auto; displa ...

  8. jQuery选择器中,通配符[id^='code']input[id$='code'][id*='code']

     1.选择器 (1)通配符: $("input[id^='code']");//id属性以code开始的所有input标签 $("input[id$='code']&qu ...

  9. 解决手机浏览器上input 输入框导致页面放大的问题(记录)

    在微信手机页面开发当中,页面是没有问题的,但是当焦点在input输入框的时候,手机页面会自动放大. 加入以下代码在head 区,可解决此问题 <meta name="viewport& ...

  10. <input type="file">上传文件并添加路径到数据库

    注:这里是用的mvc所以没法用控件 html代码 <form method="post" enctype="multipart/form-data"> ...

随机推荐

  1. C# 网页图片爬虫的几种技术基础

    一.文件流方式获取网络图片资源 方法1 , ); System.Net.WebRequest webreq = System.Net.WebRequest.Create(url); System.Ne ...

  2. [King.yue]Ext.net 弹出Windows窗体注意的事项

    页面的控件ID不能重复,否则会覆盖原控件.

  3. -Xms 和 -Xmx 不能设置的太大

    之前我一直有一个疑问,就是-Xms 和 -Xmx不是设置的越大越好吗?现在才明白怎么回事. 通过在命令行中执行 java 或者启动某种基于 Java 的中间件来运行 Java 应用程序时,Java 运 ...

  4. bzoj 1412 [ZJOI2009]狼和羊的故事(最小割)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1412 [题意] 在一个n*m的格子中,将羊和狼隔开的最小代价. [思路] 最小割. 由 ...

  5. MVC 部署出现错误未能写入输出文件xxxxxxx.

    编译器错误消息: CS0016: 未能写入输出文件“c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\ro ...

  6. 【转】Spark是基于内存的分布式计算引擎

    Spark是基于内存的分布式计算引擎,以处理的高效和稳定著称.然而在实际的应用开发过程中,开发者还是会遇到种种问题,其中一大类就是和性能相关.在本文中,笔者将结合自身实践,谈谈如何尽可能地提高应用程序 ...

  7. 在Visual Studio中利用NTVS创建Pomelo项目

    刚看新闻,才知道微软发布了Node.js Tools for Visual Studio(NTVS),受够了WebStorm输入法Bug的困扰,这下终于可以解脱了.以Pomelo为例,运行命令:pom ...

  8. 关于mac 80端口问题

    使用 maven启动 jettry时 ,jetty使用的是80端口 ,但是 mac 在1024以下的端口似乎是不让随便使用的. 在网上查了好多方式,其中的一种说是做端口转发,其实也就是把80转换成别的 ...

  9. 解决Visual Studio 2013调试时 Web服务框架中出现了无法识别的错误 问题

    此问题出现过很多次,点帮助,google, baidu 都没解决,后经过摸索解决,记录下来1.查找80port是否有被占用情况,需要查看skype[这东西不知道为什么为占用80], Reporting ...

  10. [iOS基础控件 - 3.3] 图片浏览器

    需求: 1.显示当前图片序号/总图片数 2.显示图片 3.上一张图片.下一张图片转换 4.显示图片描述     A.数据的加载方式 1.逐个加载.处理 2.使用数组.字典分离数据和逻辑 3.延迟加载 ...