laravel图片上传
2016-08-07 19:12
375 查看
html页面
php接值
完毕
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> <title>表单</title> </head> <body> <form action="{{url('file')}}" method="post" enctype="multipart/form-data"> <table border="1" align="center"> <tr> <td>昵称</td> <td><input type="text" name="name"/></td> </tr> <tr> <td>选择图片</td> <td><input type="file" name="photo"/></td> </tr> <tr> <input type="hidden" name="_token" value="<?php echo csrf_token(); ?>"> <td><input type="submit" value="提交"/></td> <td></td> </tr> </table> </form> </body> </html>
php接值
$file = Request::file('photo'); $name = Request::input('name'); $allowed_extensions = ["png", "jpg", "gif"]; if ($file->getClientOriginalExtension() && !in_array($file->getClientOriginalExtension(), $allowed_extensions)) { return ['error' => 'You may only upload png, jpg or gif.']; } $destinationPath = 'storage/uploads/'; //public 文件夹下面建 storage/uploads 文件夹 $extension = $file->getClientOriginalExtension(); $fileName = str_random(10).'.'.$extension; $file->move($destinationPath, $fileName); $filePath = asset($destinationPath.$fileName); $info=DB::insert('insert into photo(pname,photo) VALUES (?,?)',[$name,$filePath]); if($info){ return Redirect('/show'); }else{ echo "no"; }
完毕
相关文章推荐
- 在Windows 8.1的IE 11中屏蔽双击放大功能
- HTML5调用摄像头实例
- Powershell 创建炫丽美观的Html报表
- 设计模式---状态模式在web前端中的应用
- Apple官网研究之使用Justify布局导航
- 关于前端的思考与感悟
- 又被事件冒泡坑了一把,这次要彻底弄懂浏览器的事件流
- 移动端点击事件全攻略,这里的坑你知多少?
- $q 实例分析 Angular 中的 Promise
- Angular directive 实例详解
- 关于浮动与清除浮动,你应该知道的
- workerman结合laravel开发在线聊天应用的示例代码
- 通过Mootools 1.2来操纵HTML DOM元素
- jQuery Html控件基本操作(日常收集整理)
- WEB标准网页布局中尽量不要使用的HTML标签
- Flash 与 html 的一些实用技巧
- 简单对比分析Ruby on Rails 和 Laravel