【问题标题】:when uploading file in codeigniter why showing Website is currently unable to handle this request. HTTP ERROR 500在 codeigniter 中上传文件时,为什么显示网站当前无法处理此请求。 HTTP 错误 500
【发布时间】:2016-12-19 11:25:28
【问题描述】:

我有一个关于 codeigniter 的项目现在在 localhost 上运行良好,当我在 cpanel 中上传并上传文件到我的网站时,它显示的 example.com 目前无法处理此请求。 HTTP 错误 500 为什么?谁能告诉我该怎么做?

public function doupload($id,$action)
{

    $config['upload_path']          = 'SliderImages/';
    $config['allowed_types']        = 'gif|jpg|png|jpeg|psd|pdf|tiff';
    $config['overwrite']            = TRUE;
    $config['encrypt_name']         = false;
    $config['max_size']             = 10000000;
    $config['max_width']            = 999999;
    $config['max_height']           =99999;

    $this->upload->initialize($config);
    $files = $_FILES;

    if($action == "insert")
    {


            if($_FILES['slide_image']['name'] !== '')
            {

                    $_FILES['userfile']['name']= $files['slide_image']['name'];
                    $file_name = $_FILES['userfile']['name'];
                    $name =explode('.',$file_name);
                    $_FILES['userfile']['name'] = $id. '.' .$name[1];
                    $_FILES['userfile']['type']= $files['slide_image']['type'];
                    $_FILES['userfile']['tmp_name']= $files['slide_image']['tmp_name'];
                    $_FILES['userfile']['error']= $files['slide_image']['error'];
                    $_FILES['userfile']['size']= $files['slide_image']['size']; 

                    //$this->upload->do_upload();
                    if (!$this->upload->do_upload())
                    {                               
                        $error = array('error' => $this->upload->display_errors());         
                        return  $error; 
                        //print_r($error);die();
                    }
                    else
                    {
                        $msg = array('upload_data' => $this->upload->data());               
                        return $this->upload->data('file_name');

                    }

            }

    }


}

【问题讨论】:

  • 好吧,尝试检查服务器日志,或者至少激活 php 显示错误以了解有关您的问题的更多详细信息
  • 请检查您服务器的 PHP 版本是否与您的代码兼容.. 因为我们有最新版本 7.0
  • 如果设置为最新,则尝试设置为5.6 PHP版本
  • index.php 和其他文件的权限是什么?也许是 755?
  • 是文件和文件夹权限也

标签: php codeigniter cpanel


【解决方案1】:

检查系统/库/upload.php . . 找到“受保护的函数_file_mime_type” . . 修改代码

$finfo = @finfo_open(FILEINFO_MIME);
        if (is_resource($finfo)) // It is possible that a FALSE value is returned, if there is no magic MIME database file found on the system
        {
            $mime = @finfo_file($finfo, $file['tmp_name']);
            finfo_close($finfo);

            /* According to the comments section of the PHP manual page,
             * it is possible that this function returns an empty string
             * for some files (e.g. if they don't exist in the magic MIME database)
             */
            if (is_string($mime) && preg_match($regexp, $mime, $matches))
            {
                $this->file_type = $matches[1];
                return;
            }
        }

。 . 至 . .

if (function_exists('finfo_file'))
        {

            $finfo = @finfo_open(FILEINFO_MIME);            
            if (is_resource($finfo)) // It is possible that a FALSE value is returned, if there is no magic MIME database file found on the system
            {
                $mime = @finfo_file($finfo, $file['tmp_name']);
                finfo_close($finfo);

                /* According to the comments section of the PHP manual page,
                 * it is possible that this function returns an empty string
                 * for some files (e.g. if they don't exist in the magic MIME database)
                 */
                if (is_string($mime) && preg_match($regexp, $mime, $matches))
                {
                    $this->file_type = $matches[1];
                    return;
                }
            }
        }

。 . 我解决了我的错误,希望这对你也有用,cmiiw

【讨论】:

    猜你喜欢
    • 2017-12-31
    • 2018-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-18
    • 2018-01-04
    • 2020-09-16
    相关资源
    最近更新 更多