上传类CodeIgniter无法正常工作

时间:2014-10-09 03:50:10

标签: php codeigniter

使用ci上传课程遇到一些麻烦。 真的很累,但是如果有人能给我提示,那么我需要在截止日期前完成..

奇怪的是,我把指南中的样本作为起点,但它似乎并没有起作用。

控制器

public function store()
{
    $data = array();
    $data['title'] = $this->input->post('title');
    $data['text'] = $this->input->post('text');
    $data['hidden'] = $this->input->post('hidden');

            $config['upload_path'] = base_url().'user_files/pictures/';
    $config['allowed_types'] = 'gif|jpg|png|jpeg';
    $config['max_size'] = '1000';
    $config['max_width']  = '1024';
    $config['max_height']  = '768';

    $this->load->library('upload'); //initialize
            $this->upload->initialize($config);
            $this->upload->do_upload('userfile');
            $imageData = $this->upload->data();
            $data['file'] = $imageData['file_name'];

    if (!$data['hidden'])
    {
        $data['hidden'] = 0;
    }
    $data['created_at'] = date('Y-m-d H:s:i');
    $data['updated_at'] = '0000-00-00 00:00:00';
    $this->mdl_newsfeed->store($data);
    redirect('news/newsfeed_c/index');
}

表格

<form method="post" action="<?php echo base_url();?>news/newsfeed_c/store" enctype="multipart/form-data">
    <div class="input-group input-group-lg">
    <span class="input-group-addon">Title</span>
        <input type="text" class="form-control" name="title" required="required" >
    </div>
        <label for="text">Text:</label><br />
                <textarea name="text" id="text" required="required" cols="80" rows="10"></textarea><br />

        <input type="file" name="userfile" size="20" />

        <input type="submit" value="Post" class="btn btn-primary btn-lg"/>
    </form>
    <script>
        // Replace the <textarea id="editor1"> with a CKEditor
        // instance, using default configuration.
        CKEDITOR.replace( 'text' );
    </script>

1 个答案:

答案 0 :(得分:0)

尝试类似:

$config['upload_path'] = './user_files/pictures/';

在这种情况下, user_files 文件夹必须位于CodeIgniter安装的根目录,文件权限为 777