zoukankan      html  css  js  c++  java
  • 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 mpphp2AF6.tmp [error] => 0 [size] => 10469 ) ) 


    Array ( [name] => 57d79d7bN9c72bb40.jpg [type] => image/jpeg [tmp_name] => C:wamp mpphp2AF6.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 ThinkUpload(); //实例化上传类 
               $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();
            }
        }
  • 相关阅读:
    JVM之GC调优
    JVM的栈、堆
    SpringMVC及其HandlerMapping、HandlerInterceptor、HandlerAdapter等组件的原理解析
    静态代理、动态代理和CGLIB,SpringAOP中的代理
    cmd删除文件夹
    vue-router命名视图+路由嵌套
    Vue实现长按事件
    [SparkSQL] hive.exec.max.dynamic.partitions配置不起作用
    Excel分数转为百分数
    Hadoop YARN主资源调度算法
  • 原文地址:https://www.cnblogs.com/xtmp/p/6113588.html
Copyright © 2011-2022 走看看