-2

当我在本地主机上运行时,它很好。上传到 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(); 
        ?> 

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

4

2 回答 2

0

如果该文件夹用于由用户加载文件,则需要权限 777。

由您来验证通过上传脚本加载了哪些文件。您还可以使用 .htaccess 来允许或不允许从该目录执行某些文件。

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

于 2016-01-09T05:22:35.867 回答
-2

我将网络服务器上的上传文件夹更改为可写,所以现在它似乎工作了。

于 2013-03-21T15:53:41.477 回答