0

任何人都可以帮助我..只有在至少上传了 2 个文件然后第一个文件没有移动到上传文件夹时才能工作..任何人都可以帮助..这是我的代码

// 看法

<?php echo form_open_multipart($this->uri->uri_string());  ?>
    <p>
    <?php echo form_label('Image') ?>
    <input type="file" name="userfile[]" size="20" class="multi" accept="gif|jpg|png"/>
    </p>    

// 控制器

function album($id){         
    if (isset($_POST['submit']))
    {
        $config['upload_path'] = './assets/gallery/'; // server directory
        $config['allowed_types'] = 'gif|jpg|png'; // by extension, will check for whether it is an image
        $config['max_size']    = '1000'; // in kb
        $config['max_width']  = '1024';
        $config['max_height']  = '768';

        $this->load->library('upload', $config);
        $this->load->library('Multi_upload');

        $files = $this->multi_upload->go_upload();

        if ( ! $files )        
        {
            $data['error'] = $this->upload->display_errors();               
        }    
        else
        {
            $data = array('upload_data' => $files);             
        }

    }       
    $id = $this->uri->segment(3);
    $data['query']      = $this->administrator_model->getAllPhoto($id);
    $data['current']    = 'home';
    $data['side']       = 'gallery';
    $data['attr']       = 'view_album';
    $data['content']    = 'backend/administrator_manage';
    $data['sidebar']    = 'backend/home_sidebar';
    $this->load->view("backend/index", $data);
}

// 我从这里使用的多上传库

稍加修改

4

1 回答 1

0

使用纯PHP多文件上传非常简单。看看这个脚本

看法

<form method="post" action="<?php echo base_url('users/upload/'); ?>" enctype="multipart/form-data">
    <label for="upload">Select : </label>
    <input type="file" name="userfile[]" id="userfile" multiple="multiple" />
    <input type="submit" name="fsubmit" id="fsubmit" value="Upload" />
</form>

控制器

public function album($id)
{
    if (isset($_FILES['userfile']['name'])) {
        // total files //
        $count = count($_FILES['userfile']['name']);
        // all uploads //
        $uploads = $_FILES['userfile'];

        for ($i = 0; $i < $count; $i++) {
            if ($uploads['error'][$i] == 0) {
                // FCPATH = root directory project
                move_uploaded_file($uploads['tmp_name'][$i], FCPATH . 'assets/gallery/' . $uploads['name'][$i]);
                echo $uploads['name'][$i] . "\n";
            }
        }
    }
}

希望这可以帮助。谢谢!!

于 2013-02-28T03:16:28.013 回答