简体   繁体   English

在实时服务器上的Codeigniter中出现500个内部服务器错误

[英]500 internal server error in codeigniter on live server

Status Code:500 Internal Server Error 状态码:500内部服务器错误

Here is uploading file function. 这里是上传文件功能。 which work's fine on localhost but i am not sure why this error occur because file permissions are ok and upload library is loaded fine and even doesn't show any error in log file. 在localhost上可以正常工作,但是我不确定为什么会发生此错误,因为文件许可权还不错,并且上载库加载得很好,甚至在日志文件中也没有显示任何错误。

$image_file   = $this->input->post('fileToUpload');
$update_date  = date('Y-m-d');

if($_FILES['user_image']['name'] != '') {
    $filename = 'user_image';    
}

$config = array(
    'upload_path'   => './uploads',
    'allowed_types' => 'gif|jpg|png|jpeg',
    'max_size'      => '2048',
);

$upload_data = $this->do_upload($filename, $config);

$this->db->where('pkuserid',$id);
$update_array = array(
    'firstname'   => $first_name,
    'lastname'    => $last_name,
    'headlines'   => $headlines,
    'summary'     => $summary2,
    'updated_date'=> $update_date
);

if($upload_data['condition']=='error') {
    echo json_encode(array('condition'=>'error', 'message'=>$upload_data['error'].' (User image)')); exit;
} else {
    $update_array['userpicture'] = $upload_data['upload_data']['file_name'];
}

$this->db->update('tblusers', $update_array);
return $update_array;
}

public function do_upload($fieldname, $config) {
    $this->load->library('upload');
    $this->upload->initialize($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;
    }
}

Upload folder snapshot: 上传文件夹快照: 在此处输入图片说明

Any Help will be appropriated. 任何帮助都将适用。 Thanks 谢谢

You'll need a destination directory for your uploaded images. 您需要一个目标目录来上传图片。 Create a directory at the root of your CodeIgniter installation called uploads and set its file permissions to 777. 在您的CodeIgniter安装的根目录中创建一个名为uploads的目录,并将其文件权限设置为777。

$image_file   = $this->input->post('fileToUpload');
if($image_file){

     //load upload library
      $this->load->library('upload');

       // Specify configuration for File 1
        $config['upload_path'] = './uploads/';
        $config['allowed_types'] = 'gif|jpg|png|jpeg';
        $config['max_size'] = '2048';
        $this->upload->initialize($config);

        if ($this->upload->do_upload($fieldname)){
            $image_data = $this->upload->data();
            $update_array['userpicture'] = $upload_data['upload_data']['file_name'];
        }
}

I hope it will work for you. 希望它对您有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM