【问题标题】:uploading file on server response 500 internal server error in codeigniter 3在codeigniter 3中上传服务器响应500内部服务器错误
【发布时间】:2016-12-29 00:48:20
【问题描述】:

我的代码在 localhost 上运行良好,但是当我将文件上传到服务器时,我收到了这个错误 500 internal server error。

我的代码在这里:

上传方式

 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;

    }
}

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

【问题讨论】:

  • A 500 通常意味着隐藏在其后面的错误,并且 500 仅用于防止显示任何敏感信息。添加ini_set('display_errors', 1); ini_set('error_reporting', E_ALL),看看实际的错误是什么。
  • /uploads/ 可能不可写
  • error 500 内部服务器错误。这意味着您的ajax调用错误。

标签: php codeigniter upload


【解决方案1】:

代替

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

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

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

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

【讨论】:

  • 谢谢@zanderwar,我尝试了所有这些方法,但没有得到任何积极的回应。
  • 好的,你需要追踪你的error_log,这是 PHP 在致命错误时产生的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-12-03
  • 2018-02-22
  • 2012-05-01
  • 1970-01-01
相关资源
最近更新 更多