【问题标题】:How to upload multiple images in codigniter. Please any body shere code如何在 codeigniter 中上传多张图片。请任何人分享代码
【发布时间】:2015-02-09 11:40:59
【问题描述】:

如何在代码 ignite r 中上传多张图片。请任何身体剪切代码。 这是我上传在控制器中编写的文件的代码。请任何人提出此代码有什么问题。

function do_upload_slider()
   {
    $this->load->library('upload');
    $files = $_FILES;
    echo $cpt = count($_FILES['userfile']['name']);
    for($i=0; $i<$cpt; $i++)
    {

        $_FILES['userfile']['name']= $files['userfile']['name'][$i];
        $_FILES['userfile']['type']= $files['userfile']['type'][$i];
        $_FILES['userfile']['tmp_name']= $files['userfile']['tmp_name'][$i];
        $_FILES['userfile']['error']= $files['userfile']['error'][$i];
        $_FILES['userfile']['size']= $files['userfile']['size'][$i];    



    $this->upload->initialize($this->set_upload_options());
    $this->upload->do_upload_slider();


    }

}
private function set_upload_options()
{   
//  upload an image options
    $config = array();
    $config['upload_path'] = './uploads/slider/';
    $config['allowed_types'] = 'gif|jpg|png|jpeg';
    $config['max_size']      = '2048000';
    $config['overwrite']     = TRUE;


    return $config;
}

【问题讨论】:

    标签: upload


    【解决方案1】:
    try this one.it may be help you
    uploadform_view.php.
    
    
    
    <html>
    <head>
    <title>Upload Form</title>
    </head>
    <body>
    <?php echo form_open_multipart('imageupload/doupload');?>
    <input name="userfile[]" id="userfile" type="file" multiple="" />
    <input type="submit" value="upload" />
    <?php echo form_close() ?>
    </body>
    </html>
    
    Create A New Controller: controllers/imageupload.php 
    
    
         class Imageupload extends CI_Controller {
        function __construct()
        {
        parent::__construct();
        $this->load->helper(array('form', 'url'));
        }
        function index()
        {
        $this->load->view('imageupload_view', array('error' => ' ' ));
        }
        function doupload() {
        $name_array = array();
        $count = count($_FILES['userfile']['size']);
        foreach($_FILES as $key=>$value)
        for($s=0; $s<=$count-1; $s++) {
        $_FILES['userfile']['name']=$value['name'][$s];
        $_FILES['userfile']['type']    = $value['type'][$s];
        $_FILES['userfile']['tmp_name'] = $value['tmp_name'][$s];
        $_FILES['userfile']['error']       = $value['error'][$s];
        $_FILES['userfile']['size']    = $value['size'][$s];  
            $config['upload_path'] = './uploads/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size'] = '100';
        $config['max_width']  = '1024';
        $config['max_height']  = '768';
        $this->load->library('upload', $config);
        $this->upload->do_upload();
        $data = $this->upload->data();
        $name_array[] = $data['file_name'];
        }
        $names= implode(',', $name_array);
        /* $this->load->database();
        $db_data = array('id'=> NULL,
        'name'=> $names);
        $this->db->insert('testtable',$db_data);
        */ print_r($names);
        }
        }
    

    就是这样。根据您的需要定制它,基础知识已经存在。还有祝你好运!

    【讨论】:

      猜你喜欢
      • 2017-07-31
      • 1970-01-01
      • 1970-01-01
      • 2021-09-04
      • 2020-01-28
      • 1970-01-01
      • 2018-10-06
      • 1970-01-01
      相关资源
      最近更新 更多