实时服务器上的codeigniter中有500个内部服务器错误

时间:2017-01-18 09:19:43

标签: php codeigniter file-upload

状态代码:500内部服务器错误

这是上传文件功能。哪个在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;
    }
}

上传文件夹快照: enter image description here

任何帮助都将被挪用。感谢

1 个答案:

答案 0 :(得分:0)

您需要为上传的图片提供目标目录。在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'];
        }
}

我希望它对你有用。