CodeigniterPHP multi-image upload-PHP source code

Source: Internet
Author: User
CodeigniterPHP multi-image Upload Codeigniter PHP multi-image Upload

1. HTML
    

2. CSS/** multi-image display area **/. case_list {margin: 15px 20px; _ margin: 15px ;}. case_list ul {background: # fff; width: Pixel px; height: 170px; float: left; padding: 10px; margin: 12px; border: 1px solid # dddddddd ;}. case_list li {color: # f55205; font-size: 12px; font-weight: bold ;}. case_list li. t {background: url (.. /images/t.jpg) left center no-repeat; padding: 5px; padding-left: 10px ;}. case_list li a {color: # f55205; line-height: 16px ;}. case_list. Li img {width: Pixel px; height: 135px;} 3. common. php control class // jump to the upload page public function show_mul_img () {$ datas ["imgName"] = ""; $ this-> _ img_mul_view ($ datas );} function _ img_mul_view ($ datas = array () {$ this-> load-> view ("comm_page/mul_upImg", $ datas);} // multi-image upload, save the public function do_mulupImg () {$ datas ["img_lst"] = $ this-> mytool-> update_mul_obj (mymsg: DIR_MULIMG ); $ this-> _ img_mul_view ($ datas);} 4. mytool. php tool // 2012-9-6, trigger function update_mul_obj ($ filename, $ name = "userfile") {$ CI = & get_instance (); $ CI-> load-> library ('upload'); return $ CI-> upload-> do_mul_upload ($ filename, $ name );} # Here I have extended the upload method provided by CI, and implemented a multi-image upload job. 5. MY_upload.php extension to implement the upload class MY_Upload extends CI_Upload {public function _ construct () {parent ::__ construct ();} function do_mul_upload ($ filename, $ field = 'userfile') {$ CI = & get_ I Nstance (); $ count = count ($ _ FILES ["$ field"] ["name"]); // the default name of the page $ this-> upload_path = $ CI-> mytool-> get_obj_path ($ filename ); // saved path $ this-> set_allowed_types ("gif | jpg | png "); // supported Image formats $ bh = $ CI-> session-> userdata ("bh"); // The current user logged on $ file_arr = array (); for ($ I = 0; $ I <$ count; $ I ++) {// Give it a name not likely to already exist! $ Pseudo _ field_name = '_ psuedo _'. $ field. '_'. $ I; $ _ FILES [$ pseudo _ field_name] = array ('name' => $ _ FILES [$ field] ['name'] [$ I], 'size' => $ _ FILES [$ field] ['size'] [$ I], 'type' => $ _ FILES [$ field] ['type'] [$ I], 'tmp _ name' => $ _ FILES [$ field] ['tmp _ name'] [$ I], 'Error' => $ _ FILES [$ field] ['error'] [$ I]); if ($ CI-> upload-> do_upload ($ pseudo _ field_name )) {// the default name is userfile $ data = $ CI-> upload-> data (); $ in_data = array (); $ in_data ["name"] = $ data ['File _ name']; // file name $ in_data ["path"] = "$ filename/$ bh "; // Save the path $ file_arr [] = $ in_data ;}}return $ file_arr ;}6. Upload The mul_upImg.php file.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.