Codeigniter-上传目标文件夹似乎不可写

时间:2013-03-21 11:47:43

标签: php mysql codeigniter file-upload

当我在localhost上运行时,它很好。上传到server.one错误后抛出 - 即。 上载目标文件夹似乎不可写。 这是我的控制器 -

function do_upload()
    {
        $path = './uploads/';
        chmod($path,0777);
        $config['upload_path'] = $path; 
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size'] = '1000';
        $config['max_width']  = '1024';
        $config['max_height']  = '768';
        $config['encrypt_name']  = TRUE;
        $this->load->library('upload', $config);

        if ( ! $this->upload->do_upload())
        {
            $error = array('error' => $this->upload->display_errors());

            $this->load->view('upload_form', $error);
        }
        else
        {
            $this->load->library('form_validation');
            $data = array('upload_data' => $this->upload->data());
            $pic_path= 'uploads/'.$data['upload_data']['file_name'];
            $this->form_validation->set_rules('txt_title','Title','trim|required|xss_clean');
            $this->form_validation->set_rules('category', 'Select Category', 'callback_select_validate');
            $this->form_validation->set_rules('description','Description','trim|required|xss_clean');
            if($this->form_validation->run() == FALSE)
            {
                redirect('upload');
            }
            else{
            $title =mysql_real_escape_string(htmlentities($this->input->post('txt_title')));
            $category = $this->input->post('category');
            $description = mysql_real_escape_string(htmlentities($this->input->post('description')));
            $this->load->model('user');
            $suc_mesg=$this->user->insertPic($pic_path,$category,$title,$description);
            $this->load->view('upload_success', $suc_mesg);
            }
        }
    }

这是我的观点页面 -

 <?php 
        echo $error;
            echo form_fieldset('Upload Category Pics');

            echo form_open_multipart('upload/do_upload');
            echo '</br>';
            echo form_label('Title','title');
            echo '<input type="text" size="30" name="txt_title" placeholder="Enter title to pic"/>';
            echo '</br></br>';
            echo form_label('Choose Category Pics', 'category');
            $options = array(
                      'null' => '--Please Select--',
                      1  => 'Technology',
                      3    => 'Entertainment',
                      2 => 'Politics',
                      4   => 'Sports'
                    );

        echo form_dropdown('category', $options, 'category');
        echo "<br></br>";
        echo form_label('Description','description');
            $data = array(
                'name'        => 'description',
                'id'          => 'description',
                'placeholder'       => 'Enter description',
                'rows'        => '5',
                'cols'        => '40',
            );
        echo form_textarea($data);
        echo '</br></br>';
        echo form_label('Browse Pics','pics');
        echo '<input type="file" name="userfile" size="20" />';
        echo "<br></br>";
        echo '<input type="submit" value="upload" />';
        echo '</form>';
        echo form_fieldset_close(); 
        ?> 

我无法找到我的错误,哪里出错了。有人准备好帮助我吗?

2 个答案:

答案 0 :(得分:0)

如果文件夹用于由用户加载文件,则需要使用permisision 777。

由您决定通过上传脚本加载哪些文件。您也可以使用.htaccess来表示或不允许从该目录执行某些文件。

在codeigniter中上传的文档非常简单直观。此外,您还可以查看一些方法来验证上传的文件类型http://ellislab.com/codeigniter/user-guide/libraries/file_uploading.html

答案 1 :(得分:-2)

我将web服务器上的uploads文件夹更改为可写,所以现在它似乎正常工作。