上传多张图片时 ,对 $_FILES 的处理. upload
Posted cb_za
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了上传多张图片时 ,对 $_FILES 的处理. upload相关的知识,希望对你有一定的参考价值。
上传多张图片, 要对 $_FILES进行 重新处理.
1 //添加 2 public function addCourseAlbumAction() 3 { 4 $CourseAlbumModel = new CourseAlbumModel(); 5 $CourseAlbumModel->title = $_REQUEST["title"]; 6 $CourseAlbumModel->courseId = $_REQUEST["courseId"]; 7 if(!empty($_FILES)) 8 { 9 10 $tempArr = $_FILES["url"]; 11 $imageArr = array(); 12 13 foreach ($tempArr as $k => $v) 14 { 15 foreach ($v as $k2 => $v2) 16 { 17 $imageArr[$k2][$k] = $v2; 18 } 19 } 20 21 foreach ($imageArr as $k => $v) 22 { 23 $upload = new BaseUploadUtil(); 24 $upload->createPath(); 25 $upload->createDatePath(); 26 $upload->file = $v; 27 $info = $upload->upload(); 28 if(count($info)>0){ 29 $CourseAlbumModel->url = $info["path"]; 30 } 31 $CourseAlbumModel->orderBy = $_REQUEST["orderBy"]; 32 $CourseAlbumModel->lastUpdateTime = time(); 33 $CourseAlbumModel->insert(); 34 } 35 36 echo 1; 37 38 } 39 else 40 { 41 $CourseAlbumModel->orderBy = $_REQUEST["orderBy"]; 42 $CourseAlbumModel->lastUpdateTime = time(); 43 echo $CourseAlbumModel->insert(); 44 } 45 46 }
关键代码:
1 $tempArr = $_FILES["url"]; 2 $imageArr = array(); 3 4 foreach ($tempArr as $k => $v) 5 { 6 foreach ($v as $k2 => $v2) 7 { 8 $imageArr[$k2][$k] = $v2; 9 } 10 } 11 12 foreach ($imageArr as $k => $v) 13 { 14 $upload = new BaseUploadUtil(); 15 $upload->createPath(); 16 $upload->createDatePath(); 17 $upload->file = $v; 18 $info = $upload->upload(); 19 20 }
处理后的 数组是 $imageArr. 之后 每次上传 就是 $upload->file = $v;
以上是关于上传多张图片时 ,对 $_FILES 的处理. upload的主要内容,如果未能解决你的问题,请参考以下文章