上传文件服务器响应500内部服务器错误在codeigniter 3

时间:2016-12-29 00:48:20

标签: php codeigniter upload

我的代码在localhost上工作正常,但是当我将文件上传到服务器时,我收到此错误500内部服务器错误。

我的代码在这里:

上传方法

 public function do_upload($fieldname)
{
    $config['upload_path']          = './uploads/';
    $config['allowed_types']        = 'jpg|png';
    $config['max_size']             = 10000;
    /*$config['max_width']            = 1024;
    $config['max_height']           = 768;*/
    //echo '<pre>'; print_r($config); exit;  //this array responding Ok but the issue is in the bottom codintion.

    $this->load->library('upload', $config);

    if ( ! $this->upload->do_upload($fieldname))
    {

        $error = array('condition'=>'error', 'error' => $this->upload->display_errors());
        return $error;
    }
    else
    {

        $data = array('condition'=>'success', 'upload_data' => $this->upload->data());
        return $data;

    }
}

任何帮助将不胜感激。谢谢

1 个答案:

答案 0 :(得分:0)

而不是

$config['upload_path']          = './uploads/';

尝试使用完整路径:例如/var/www/public_html/uploads

$config['upload_path']          = $_SERVER['DOCUMENT_ROOT'] . '/uploads/';

还要确保您的/uploads/目录可写