【问题标题】:Upload file and save its path in database using codeingiter使用 codeigniter 上传文件并将其路径保存在数据库中
【发布时间】:2016-09-01 05:40:58
【问题描述】:

我希望将文件上传到文件夹,然后将其路径保存在数据库中,但我只卡在第一步

每当我尝试上传文件时,我都会收到一条消息

您没有选择要上传的文件

我使用的代码是

查看

<?php
    echo form_open_multipart('recruiter/adddata); 

       $data = array(
           'type'=>'file',
           'name'=>'userfile',
           'class'=>'fileinput btn-info',
           'id'=>'filename3',
           'data-filename-placement'=>'inside',
           'title'=>'Resume'
       );

       echo form_upload($data); 

        $data = array(
            'type'=>'submit',
            'class'=>'btn btn-danger',
            'name'=>'submit',
            'content'=>'Submit'

        );
        echo form_button($data); 

    echo form_close(); 
?>

控制器

$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'doc|docx|pdf';
$config['max_size'] = 10000;
$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());
        print_r($error); //only for checking purposes
    }
else
    {
        $data = array('upload_data' => $this->upload->data());
        print_r($data); //only for checking purposes
    }

谁能告诉我如何上传文件并将其路径保存在数据库中

【问题讨论】:

  • 改变你的回声 form_open('recruiter/adddata);回显 form_open_multipart('recruiter/adddata');我希望它会起作用。
  • @Kabir Hossain 不工作
  • 如果不起作用只是给出错误,那么我们将为您提供下一个解决方案。将 if ( !$this->upload->do_upload('userfile')) 更改为 $input_file= "userfile" // 输入名称="userfile" if(!$this->upload->do_upload($input_file) )
  • @Kabir Hossain 试过,但我仍然遇到同样的错误。 "您没有选择要上传的文件"
  • 更改 $config['allowed_types'] = 'doc|docx|pdf';到 $config['allowed_types'] = '*';

标签: php codeigniter file-upload


【解决方案1】:

进行一些更改,例如:

echo form_upload($data); 

<?php echo form_open_multipart();?>

控制器功能部分:

//start of file upload code
$config['upload_path'] = './uploads/';
$config['allowed_types'] = '*';
$this->load->library('upload', $config);
$this->upload->do_upload();
$data = $this->upload->data();
//end of file upload code

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-02-09
    • 1970-01-01
    • 2012-07-26
    • 1970-01-01
    • 1970-01-01
    • 2023-04-09
    • 1970-01-01
    相关资源
    最近更新 更多