上传多张图片时 ,对 $_FILES 的处理. upload

2021-06-19 00:06

阅读:428

标签:derby   orderby   mode   ase   inf   info   url   代码   color   

 

上传多张图片, 要对 $_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

标签:derby   orderby   mode   ase   inf   info   url   代码   color   

原文地址:http://www.cnblogs.com/cbza/p/7196092.html


评论


亲,登录后才可以留言!