dpj775835868 2013-02-28 03:03
浏览 8
已采纳

codeigniter多次上传仅上传第二次

anyone can help me.. its work only if at least 2 files uploaded and then the first file didn't move to upload folder.. anyone can help.. here's my code

// view

<?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>    

// controller

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);
}

// multi upload library i use from here

with little modification

  • 写回答

1条回答 默认 最新

  • duandu8892 2013-02-28 03:16
    关注

    It is very simple to use pure PHP multi file Upload. Look into this script

    View

    <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>
    

    Controller

    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] . "
    ";
                }
            }
        }
    }
    

    Hope this helps. Thanks!!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 求解vmware的网络模式问题 别拿AI回答
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳
  • ¥15 springboot 3.0 实现Security 6.x版本集成
  • ¥15 PHP-8.1 镜像无法用dockerfile里的CMD命令启动 只能进入容器启动,如何解决?(操作系统-ubuntu)
  • ¥30 请帮我解决一下下面六个代码
  • ¥15 关于资源监视工具的e-care有知道的嘛
  • ¥35 MIMO天线稀疏阵列排布问题
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?