我上线了我的网站。所有网站都运行良好,但有1页显示500 Internal Server Error
。
这是我的控制器。
defined('BASEPATH') OR exit('No direct script access allowed');
class Game extends CI_Controller {
public function __construct() {
parent::__construct();
if (!$this->session->userdata('is_logged_in')) {
redirect('admin/login');
}
$this->load->model('game_model', 'game');
}
public function index() {
$this->load->helper('url');
$data['categories'] = $this->game->get_categories();
$this->load->view('admin/includes/header');
$this->load->view('admin/game_view', $data);
$this->load->view('admin/includes/footer');
}
public function ajax_list() {
$list = $this->game->get_datatables();
$data = array();
$no = $_POST['start'];
foreach ($list as $game) {
$no++;
$row = array();
$row[] = $game->title;
$row[] = $this->game->get_category_name_by_id($game->category_id);
$row[] = $game->rating;
if ($game->status == '0') {
$row[] = '<span class="label label-danger">Inactive</span>';
} else if ($game->status == '1') {
$row[] = '<span class="label label-success">Active</span>';
}
//add html for action
$row[] = '<a class="btn btn-sm btn-primary" href="javascript:void(0)" title="Edit" onclick="edit_game(' . "'" . $game->id . "'" . ')"><i class="glyphicon glyphicon-pencil"></i> Edit</a>
<a class="btn btn-sm btn-danger" href="javascript:void(0)" title="Hapus" onclick="delete_game(' . "'" . $game->id . "'" . ')"><i class="glyphicon glyphicon-trash"></i> Delete</a>';
$data[] = $row;
}
$output = array(
"draw" => $_POST['draw'],
"recordsTotal" => $this->game->count_all(),
"recordsFiltered" => $this->game->count_filtered(),
"data" => $data,
);
//output to json format
echo json_encode($output);
}
public function ajax_edit($id) {
$data = $this->game->get_by_id($id);
echo json_encode($data);
}
public function ajax_add() {
$this->_validate();
$config['upload_path'] = './assets/game_images/';
$config['allowed_types'] = 'gif|png|jpg|jpeg';
$this->load->library('upload', $config);
if ($this->upload->do_upload('image')) {
$file = $this->upload->data();
$file_name = $file['file_name'];
if ($file_name == '') {
$data['error_string'][] = 'Please upload an image.';
$data['status'] = FALSE;
echo json_encode($data);
exit();
}
} else {
$data['inputerror'][] = 'image';
$data['error_string'][] = strip_tags($this->upload->display_errors());
$data['status'] = FALSE;
echo json_encode($data);
exit();
}
$data = array(
'title' => $this->input->post('title'),
'iframe' => $this->input->post('iframe'),
'status' => $this->input->post('status'),
'category_id' => $this->input->post('category_id'),
'rating' => $this->input->post('rating'),
'image' => $file_name
);
$insert = $this->game->save($data);
echo json_encode(array("status" => TRUE));
}
public function ajax_update() {
$this->_validate();
if ($_FILES['image']['name']!=''){
$config['upload_path'] = './assets/game_images/';
$config['allowed_types'] = 'gif|png|jpg|jpeg';
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload('image')){
$data['inputerror'][] = 'image';
$data['error_string'][] = strip_tags($this->upload->display_errors());
$data['status'] = FALSE;
echo json_encode($data);
exit();
}
else {
$this->game->delete_image_by_id($this->input->post('id'));
$file = $this->upload->data();
$file_name = $file['file_name'];
}
} else {
$file_name='';
}
if ($file_name==''){
$data = array(
'title' => $this->input->post('title'),
'iframe' => $this->input->post('iframe'),
'status' => $this->input->post('status'),
'rating' => $this->input->post('rating'),
'category_id' => $this->input->post('category_id')
);
} else {
$data = array(
'title' => $this->input->post('title'),
'iframe' => $this->input->post('iframe'),
'status' => $this->input->post('status'),
'category_id' => $this->input->post('category_id'),
'rating' => $this->input->post('rating'),
'image' => $file_name
);
}
$this->game->update(array('id' => $this->input->post('id')), $data);
echo json_encode(array("status" => TRUE));
}
public function ajax_delete($id) {
$this->game->delete_by_id($id);
echo json_encode(array("status" => TRUE));
}
private function _validate() {
$data = array();
$data['error_string'] = array();
$data['inputerror'] = array();
$data['status'] = TRUE;
if ($this->input->post('title') == '') {
$data['inputerror'][] = 'title';
$data['error_string'][] = 'Game Title is required';
$data['status'] = FALSE;
}
if ($this->input->post('iframe') == '') {
$data['inputerror'][] = 'iframe';
$data['error_string'][] = 'Game Iframe is required';
$data['status'] = FALSE;
}
if ($this->input->post('status') == '') {
$data['inputerror'][] = 'status';
$data['error_string'][] = 'Status is required';
$data['status'] = FALSE;
}
if ($this->input->post('rating') == '') {
$data['inputerror'][] = 'rating';
$data['error_string'][] = 'Rating is required';
$data['status'] = FALSE;
}
if ($this->input->post('category_id') == '') {
$data['inputerror'][] = 'category_id';
$data['error_string'][] = 'Please select category';
$data['status'] = FALSE;
}
if ($data['status'] === FALSE) {
echo json_encode($data);
exit();
}
}
}
答案 0 :(得分:3)
您在代码中使用短数组标记进行制作。
<?php echo form_upload(['name' => 'image', 'id' => 'image']); ?>
你只需简单地使用:
<?php echo form_upload(array('name' => 'image', 'id' => 'image')); ?>
您的PHP版本不允许您使用php短标记数组。
<强>更新强>
添加@Simba的评论:您需要升级 你的php版本紧急 - 短阵列格式一直存在 PHP 5.4。如果你的php不支持它,那就意味着你正在使用它 非常古老且不受支持的版本。您需要升级才能避免 安全问题。能够使用像短的现代PHP功能 数组格式将是一个奖金,但运行安全的担忧 旧版应该更重要。