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

 

posted @ 2016-11-29 14:46  虚幻的街景  阅读(209)  评论(0编辑  收藏  举报