input type=file 图片上传相关
HTML:
<input type="file" name="address" onchange='PreviewImage(this)' value=""/>
PHP:
print_r($_FILES);
echo "<br/>";
print_r($_FILES['address']); echo "<br/>";
print_r($_FILES['address']['name']);
Array ( [address] => Array ( [name] => 57d79d7bN9c72bb40.jpg [type] => image/jpeg [tmp_name] => C:\wamp\tmp\php2AF6.tmp [error] => 0 [size] => 10469 ) )
Array ( [name] => 57d79d7bN9c72bb40.jpg [type] => image/jpeg [tmp_name] => C:\wamp\tmp\php2AF6.tmp [error] => 0 [size] => 10469 )
57d79d7bN9c72bb40.jpg
附示例:
function upd($id){
//查询被修改商品信息,并展示
$newsinfo=M('productbase');
if(!empty($_POST)){
$newsinfo->create();
print_r($_FILES);
echo "<br/>";
print_r($_FILES['address']); echo "<br/>";
print_r($_FILES['address']['name']);
if(!empty($_FILES['address']['name'])){
// //上传图片
$upload = new \Think\Upload(); //实例化上传类
$upload->maxSize = 3145728 ; //设置附件上传大小
$upload->exts = array('jpg', 'gif', 'png', 'jpeg'); //设置附件上传类型
$upload->autoSub = false;
$upload->savePath = './public/product/'; //设置附件上传目录 上传文件
$info = $upload->upload();
if(!$info) { //上传错误提示错误信息
$this->error($upload->getError()); }else{ //上传成功
$filename= $info['address']['savename'];
}
$newsinfo->address=$filename;
}
$product->time=time();
$z= $newsinfo->save();
if($z){
$this->success("商品修改成功",U('Admin/Product/showlist'));
}else{
$this->error("商品修改失败",U("Admin/Product/showlist"));
}
}else{
//获取商品ID对应的栏目名
$cid=$newsinfo->where('id='.$id)->getField('cid');//对应navclass的id
$newsnavname=M('navclass')->where('id='.$cid)->getField('name');
$this->assign('id',$cid);
$this->assign('newsnavname',$newsnavname);
//获取navclass中的所有分类名
$map['url']='Home/List/productlist';
$productLanmu=M('navclass')->where($map)->select();
$this->assign('productLanmu',$productLanmu);
//联表查询出新闻标题和内容
$info =$newsinfo->where('id='.$id)->find();
//$info = $Product->find($Product_id);
$this->assign('info',$info);
$this -> display();
}
}
input type=file 图片上传相关的更多相关文章
- js 实现 input type="file" 文件上传示例代码
在开发中,文件上传必不可少但是它长得又丑.浏览的字样不能换,一般会让其隐藏点其他的标签(图片等)来时实现选择文件上传功能 在开发中,文件上传必不可少,<input type="file ...
- [置顶] js 实现 <input type="file" /> 文件上传
在开发中,文件上传必不可少,<input type="file" /> 是常用的上传标签,但是它长得又丑.浏览的字样不能换,我们一般会用让,<input type ...
- input type="file"文件上传到后台读取
html页面(表单采用bootStrap) js部分: //更换头像时把上传的图片post方式到控制器 <script type="text/javascript"> ...
- input[type='file']获取上传文件路径案例
最近在项目时,需要获取用户的上传文件的路径,便写了一个demo: <body> <input type="file" name="" valu ...
- <input type="file">文件上传
<input> type 类型为 file 时使得用户可以选择一个或多个元素以提交表单的方式上传到服务器上,或者通过 Javascript 的 File API 对文件进行操作 . 常用i ...
- input type='file'限制上传文件类型
前端与后台数据进行对接时,就避免不了要使用ajax进行http请求,常用的请求就两个post与get:然而常见的post请求的需求是文件上传,可能我一说到文件上传大家都觉得so easy啊,没什么嘛 ...
- javascript input type=file 文件上传
在JS中,input type=file 是常用的文件上传API,但感觉W3C说的不是很清楚,同时网上的资料也比较乱. 由于做微信开发,所以网页打算尽量少用第三方库或者插件,以加快网页的加载速度.因为 ...
- input type file onchange上传文件的过程中,遇到同一个文件二次上传无效的问题。
不要采用删除当前input[type=file]这个节点,然后再重新创建dom这种方案,这样是不合理的.解释如下:input[type=file]使用的是onchange去做,onchange监听的为 ...
- input type='file'文件上传自定义样式
使用场景: 在未使用UI库时免不了会用到各种上传文件,那么默认的上传文件样式无法达到项目的要求,因此重写(修改)上传文件样式是必然的,下面的效果是最近项目中自己写的一个效果,写出来做个记录方便以后使用 ...
随机推荐
- 深入理解javascript原型和闭包(6)——继承
为何用“继承”为标题,而不用“原型链”? 原型链如果解释清楚了很容易理解,不会与常用的java/C#产生混淆.而“继承”确实常用面向对象语言中最基本的概念,但是java中的继承与javascript中 ...
- 【PHP发展史】PHP5.2 到 PHP5.6 中新增的功能详解
截至目前(2014.2), PHP 的最新稳定版本是 PHP5.5, 但有差不多一半的用户仍在使用已经不在维护的 PHP5.2, 其余的一半用户在使用 PHP5.3. 因为 PHP 那“集百家之长”的 ...
- PHP常量详解:define和const的区别
常量是一个简单值的标识符(名字).如同其名称所暗示的,在脚本执行期间该值不能改变(除了所谓的魔术常量,它们其实不是常量).常量默认为大小写敏感.通常常量标识符总是大写的. 可以用 define() 函 ...
- JsonFormatter PrettyPrint
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- php的register_globals配置
1.需求 看ci文档的时候,看到register_globals,要了解这个配置的使用 2.分析 register_globals是PHP.ini里的一个配置,这个配置影响到php如何接收传递过来的参 ...
- Java 网络编程之 Socket
========================UDP============================= UDP---用户数据报协议,是一个简单的面向数据报的运输层协议. UDP不提供可靠性, ...
- espcms简约版的表单,提示页,搜索列表页
模板/lib/form.html <script type="text/javascript" src="{%$rootdir%}js/My97DatePicker ...
- NHibernate简单使用介绍
1.在数据库中新建表格,并插入记录,SQL如下: USE WFC_DB GO create table Students ( Id ,) not null, Name ), Age int, Scor ...
- servlet 之request
request对象中其他功能 一.转发和包含 转发==>用于一个servlet和一个jsp合作处理 servlet用于处理逻辑.jsp用于显示 ...
- 错误:The method replace(int, Fragment) in the type FragmentTransaction is not applicable for the arguments (int, MyFragment)
Fragment newfragment =new MyFragment();fragmentTransaction.replace(R.layout.activity_main,newfragmen ...