【问题标题】:Codeigniter- The upload destination folder does not appear to be writableCodeigniter - 上传目标文件夹似乎不可写
【发布时间】:2013-03-10 21:53:14
【问题描述】:

当我在 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(); 
        ?> 

我找不到我的错误,到底哪里错了。请问有人愿意帮助我吗?

【问题讨论】:

  • 你确定你的上传文件夹是可写的吗?我看到你正在尝试 chmod 但你有权限吗?您的 PHP 用户可能无法对其进行 chmod .. 为此您可能需要手动更改它。
  • 手动更改您的上传文件夹权限!
  • 我不知道如何检查我的上传文件夹是否可写。请告诉我。
  • 您好 DBK,如何手动更改上传文件夹权限,告诉我
  • 如果你使用的是 Ubuntu,那么语法是 sudo chmod 777 -R /path/to/upload/folder

标签: php mysql codeigniter file-upload


【解决方案1】:

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

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

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

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 2013-10-26
      • 2016-09-13
      • 2011-03-17
      • 1970-01-01
      • 2011-08-11
      • 2017-03-24
      • 2013-05-17
      • 2018-01-26
      • 2012-01-29
      相关资源
      最近更新 更多