上傳多張圖片時 ,對 $_FILES 的處理. upload

來源:互聯網
上載者:User

標籤: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         else40         {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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.