duanhao5038 2014-01-06 19:06
浏览 44
已采纳

无法以codeigniter文本格式上传文件

I have a text form that works and I have a file uploading form that works using the exact example from the codeigniter docs, but I don't seem to be able to put the two together.

I want a form that allows text and file upload. The text should go to the database and the file to storage with filepath saved in the DB.

  • 写回答

1条回答 默认 最新

  • dss67853 2014-01-07 06:37
    关注

    The Form you need:

    <?php echo form_open_multipart('upload/do_upload');?>
       Text: <input type="text" name="usertext" size="20" />
       <br /><br />
       File: <input type="file" name="userfile" size="20" />
       <br /><br />
       <input type="submit" value="upload" />
    <?php echo form_close();?>
    

    in upload controller:

    function do_upload()
    {
        $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);
        if ( ! $this->upload->do_upload('userfile'))
        {
            $error = array('error' => $this->upload->display_errors());
            // upload error area
        }
        else
        {
            $data = array('upload_data' => $this->upload->data());
            //upload success area
    
            $userfile = $upload_data['file_name']; // the uploaded file name
    
            $usertext = $this->input->post('usertext'); // the text from form
    
            // Here you can insert the value of $usertext to db
    
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 iOS开发关于快捷指令截屏后如何将截屏(或从截屏中提取出的文本)回传给本应用并打开指定页面
  • ¥15 unity连接Sqlserver
  • ¥15 图中这种约束条件lingo该怎么表示出来
  • ¥15 VSCode里的Prettier如何实现等式赋值后的对齐效果?
  • ¥15 流式socket文件传输答疑
  • ¥20 keepalive配置业务服务双机单活的方法。业务服务一定是要双机单活的方式
  • ¥50 关于多次提交POST数据后,无法获取到POST数据参数的问题
  • ¥15 win10,这种情况怎么办
  • ¥15 如何在配置使用Prettier的VSCode中通过Better Align插件来对齐等式?(相关搜索:格式化)
  • ¥100 在连接内网VPN时,如何同时保持互联网连接