Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/244.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 无法将多个图像上载到其上载文件夹_Php_Codeigniter - Fatal编程技术网

Php 无法将多个图像上载到其上载文件夹

Php 无法将多个图像上载到其上载文件夹,php,codeigniter,Php,Codeigniter,从我下面的代码中,我试图上传4张图片,但我只能将最后一张图片上传到我的上传文件夹中 我的图像验证和所有其他任务工作正常。但只有我有多张图片上传到它的文件夹的问题 请检查我下面的代码并帮助解决我的问题 MyController.php class Booksetups extends CI_Controller { public function __construct() { parent:: __construct(); $this->l

从我下面的代码中,我试图上传4张图片,但我只能将最后一张图片上传到我的
上传
文件夹中

我的图像验证和所有其他任务工作正常。但只有我有多张图片上传到它的文件夹的问题

请检查我下面的代码并帮助解决我的问题

MyController.php

class Booksetups extends CI_Controller  {
    public function __construct()
    {
        parent:: __construct();
        $this->load->helper('url');
        $this->load->helper('form');
        $this->load->library('session');
        $this->load->model('Booksmodel');
        $this->load->library('form_validation');
        $this->load->library('pagination');
    }

    public function valid_upload()
    {
        $this->load->library('upload');

        $config['upload_path'] = 'uploads/';
        $config['allowed_types'] = 'gif|jpg|jpeg|png';
        $config['max_size']         =   2048;
        $config['max_width']        =   385;
        $config['max_height']       =   410;

        $this->upload->initialize($config);

        if (!$this->upload->validate_upload('img1')  || !$this->upload->validate_upload('img2')  || !$this->upload->validate_upload('img3')  || !$this->upload->validate_upload('img4') ) {
            $this->form_validation->set_message('valid_upload', $this->upload->display_errors());
            return FALSE;
        } else {
            return TRUE;
        }
    }


    function book($book_id = 0)
    {
        $config = array();
        $config['base_url'] = 'http://localhost/thebestbookfinder.com/Booksetups/book/pgn/';
        $config["total_rows"] = $this->Booksmodel->record_count();
        $config['uri_segment'] = 4;
        $config['per_page'] = 17;
        $config['full_tag_open'] = '<div id="pagination">';
        $config['full_tag_close'] = '</div>';


        $this->pagination->initialize($config);
        $page = ($this->uri->segment(4)) ? $this->uri->segment(4) : 0;


        $this->form_validation->set_error_delimiters('<div  class="error">', '</div>')->set_rules('book_title', '"Title"','trim|required|min_length[4]|max_length[150]|xss_clean');
        $this->form_validation->set_error_delimiters('<div  class="error">', '</div>')->set_rules('edition_id', '"Edition Name"','trim|min_length[1]|max_length[150]|xss_clean');



        //---------------------validating images---------------------------

        $this->form_validation->set_rules('img1', 'Image 1', 'trim|xss_clean|callback_valid_upload');
        $this->form_validation->set_rules('img2', 'Image 2', 'trim|xss_clean|callback_valid_upload');
        $this->form_validation->set_rules('img3', 'Image 3', 'trim|xss_clean|callback_valid_upload');
        $this->form_validation->set_rules('img4', 'Image 4', 'trim|xss_clean|callback_valid_upload');



        //-----------Here i am uploading my images into my specified folder-------------------------------
        if ($this->form_validation->run() === TRUE) {
            $this->upload->do_upload('img1');
            $this->upload->do_upload('img2');
            $this->upload->do_upload('img3');
            $this->upload->do_upload('img4');
            $this->Booksmodel->entry_insert();
            $this->session->set_flashdata('msg', '1 row(s) inserted.');
            redirect(current_url());
        }
        ................
        ................
MyViewForm.php

<?php echo form_open_multipart('Booksetups/book');?>

<?php echo form_hidden('book_id',$fbook_id['value']);?>

<input type="file" name="img1" />
<input type="file" name="img2" />
<input type="file" name="img3" />
<input type="file" name="img4" />
<?php 
    echo  form_submit($submitbtn);
    echo form_reset($resetbtn);
?>

<?php echo form_close();?>                   

使用uploadify jquery插件。它易于使用,并且完全定制了实时进度条和更多功能


使用uploadify jquery插件。它易于使用,并且完全定制了实时进度条和更多功能


调试您的do_upload函数,您没有在任何地方使用局部变量$field

调试您的do_upload函数,您没有在任何地方使用局部变量$field

也许我是个老朋友,但我只是喜欢上传一个只需2分钟编程和最多20行代码的图像。@MihaiIorga你是什么意思?:)我只是在评论讨厌“新一代”上传脚本。:)我想你对文件的所有输入都有相同的字段名,因此它是最后一个。你能显示你的视图表单吗?也许我是个老朋友,但我只是喜欢上传一个只花了大约2分钟编程和最多20行代码的图像。@MihaiIorga你是什么意思?:)我只是在评论讨厌“新一代”正在上载脚本。:)我认为您对文件的所有输入都有相同的字段名,因此它取最后一个。您能显示您的视图表单吗?
<?php echo form_open_multipart('Booksetups/book');?>

<?php echo form_hidden('book_id',$fbook_id['value']);?>

<input type="file" name="img1" />
<input type="file" name="img2" />
<input type="file" name="img3" />
<input type="file" name="img4" />
<?php 
    echo  form_submit($submitbtn);
    echo form_reset($resetbtn);
?>

<?php echo form_close();?>