【php】多图上传

 
 
 $file = $_FILES['myfile'];  //得到传输的数据,以数组的形式
// print_r($_FILES);
 $name = $file['name'];      //得到文件名称,以数组的形式


 $upload_path = "../css/foodPic/"; //上传文件的存放路径


 foreach ($name as $k=>$names){
     $type = strtolower(substr($names,strrpos($names,'.')+1));//得到文件类型,并且都转化成小写
     $allow_type = array('jpg','jpeg','gif','png'); //定义允许上传的类型
     //把非法格式的图片去除
     if (!in_array($type,$allow_type)){
         unset($name[$k]);
     }
 }
 $str = '';
 $storePic=array($storeDetailPic1,$storeDetailPic2,$storeDetailPic3);

       foreach ($name as $k=>$item){
            $type = strtolower(substr($item,strrpos($item,'.')+1));//得到文件类型,并且都转化成小写
             if (move_uploaded_file($file['tmp_name'][$k],$upload_path.time().$name[$k])){

             $storePic[$k]="http://127.0.0.1/hyn/app/css/foodPic/".time().$name[$k];
             }else{
                echo 'failed';
             }
       }



  $scope.addPic1=function(){
        console.log("1111111111");
        let addBtn =  document.getElementById('addBtn');
        let input = document.createElement("input");
        input.type = 'file';
        input.name = 'myfile[]';
        let picInut = document.getElementById('picInput');
        picInut.appendChild(input);
        if(picInut.children.length == 4){
            addBtn.disabled = 'disabled';
        }
    }
<input type="hidden" name="MAX_FILE_SIZE" value="1000000">
            <div id="picInput">
            <label>上传店铺详情图:</label><input type="file" name='myfile[]'>
            </div>
            <input id="addBtn" type="button" ng-click="addPic1()" value="继续添加图片"><br/><br/>


发布了22 篇原创文章 · 获赞 3 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/floracuu/article/details/80488621