Blogger Information
Blog 40
fans 0
comment 0
visits 45635
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
Thinkphp3.2多图上传
无須終有的博客
Original
846 people have browsed it

//html 文件
------------------------------------------------------------------------------------------------------------------------------------------------------
 <form action="{:U('Product/addproduct')}" method="post" class="layui-form layui-form-pane" enctype="multipart/form-data">
     <input id="goods_pic" name="goods_pic[]" type='file' multiple="multiple"  placeholder="" class="layui-input">
<form>
------------------------------------------------------------------------------------------------------------------------------------------------------
 //php文件方法
------------------------------------------------------------------------------------------------------------------------------------------------------

public function addproduct()

{

if(IS_POST){

if(empty($_FILES['goods_pic']['name'][0])){

           $this->error('至少上传一张图片');

         }


          // dump($_FILES);die;

         foreach ($_FILES['goods_pic']['size'] as $key => $value) {

         if($value>=3000000){

         $this->error('图片大小超出限制');

         }

         }

        

        if($_FILES['goods_pic']['error'][0] == 0){

          $config=array(

          'maxSize'=>3000000,

          'exts' =>array('jpg','png','gif'),

          'rootPath'=>'./Uploads/'

          );

          $uploader=new \Think\Upload($config);

          $result=$uploader->upload();

         

          if(!$result){

            echo $uploader->getError();

            }else{


              //上传成功

              $product_model=D('Product');

              $from=$product_model->create();

              if(empty($from['name'])){

               $this->error('产品名字未填写');

              }else if(empty($from['englishname'])){

               $this->error('产品英文名字未填写');

              }else if(empty($from['model'])){

               $this->error('产品型号未填写');

              }else if(empty($from['describ'])){

               $this->error('产品描述未填写');

              }

              $results=array();

              $rootPath=$config['rootPath'];

              $b=$rootPath.$result[0]['savepath'].$result[0]['savename'];

              foreach ($result as $key => $value) {

              $a.="#".$rootPath.$result[$key]['savepath'].$result[$key]['savename'];

              }


              $from['img1']=$a;

             

              $from['img2']=$b;

              $from['addtime']=time();

              $neiront=$from['describ'];

           $from['describ']=str_replace("\n","<br>",$neiront); 

              $res=$product_model->add($from);

              if($res){

                $this->success('添加成功');

              }else{

                $this->error('添加失败');

              }

          }

        }

         //

}else{

$this->display();

}

}

-----------------------------------------------------------------------------------------------------------------------------------------
 //存到数据表中显示
------------------------------------------------------------------------------------------------------------------------------------------------------
#./Uploads/2018-06-06/5b177dd155d4a.jpg#./Uploads/2018-06-06/5b177dd1568bc.jpg#./Uploads/2018-06-06/5b177dd15705d.jpg#./Uploads/2018-06-06/5b177dd1577fe.jpg#./Uploads/2018-06-06/5b177dd159682.jpg

------------------------------------------------------------------------------------------------------------------------------------------------------
//在页面输出  php 文件方法
------------------------------------------------------------------------------------------------------------------------------------------------------

public function product_info()

    {

        $id = I('get.id');

        $product_model = D('Product');

        $list = $product_model->where('id = '.$id)->find();

        $result[] = explode("#",$list['img1']);//多张图片用#分开

        // dump($result);die;

        $this->assign('list',$list);

        $this->assign('img',$result);

        $this->display();

    }

 ------------------------------------------------------------------------------------------------------------------------------------------------------

//html页面 展示
 ------------------------------------------------------------------------------------------------------------------------------------------------------

<foreach name="img" item="vo">

<volist name="vo" id="vl" offset="1">

    <div class="swiper-slide">

        <img src="{$vl|ltrim='.'}" />

    </div>

</volist>

</foreach>

 ------------------------------------------------------------------------------------------------------------------------------------------------------

   


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post