CodeIgniter 突然无法上传图像,并说不能为空



向大家致意,尤其是CodeIgniter开发人员的资深人士。

我对从CodeIgniter构建的网站有问题(我不是以前的epmployer继承的开发人员)。本网站无法正常工作,尤其是在上传图像并显示警告时

错误号: 1048 列"article_image"不能为空

我确实尝试在脚本和数据库上找到问题,但没有任何变化,因为没有人更改代码和内容。今天,我再次尝试将"Null"更改为"是"(以前是"否"),并尝试上传文章。它正在工作是奇迹,但下一个问题是图像消失(损坏)。我搜索其他人并寻找与我有相同问题的人说我需要升级 CodeIgniter。我的是 3.0.0,而最新的是 3.1.10。我将内容复制粘贴到/System 和/views/error/cli 中,没有变得更好,但会变得更糟,网页上的图像消失了(丢失)。

这是我的Article_model

defined('BASEPATH') OR exit('No direct script access allowed');
class Article_model extends CI_Model {
public function get_all()
{
// $this->db->order_by('article_date', 'desc');
// $this->db->order_by('article_view', 'desc');
// $query = $this->db->get_where('article', array('flag !=' => 3));
// return $query->result_array();
$query = $this->db->query("SELECT A.*,B.*, A.id AS id_article FROM article AS A JOIN category B ON A.article_category = B.id WHERE A.flag != 3 ORDER BY article_date DESC, article_view DESC ");
return $query->result_array();
}
public function check($article_id)
{
$query = $this->db->get_where('article', array('flag !=' => 3, 'id' => $article_id));
return $query->row_array();
}
public function get_category()
{
$query = $this->db->order_by('category_name', 'ASC')->get_where('category', array('flag' => 1));
return $query->result_array();
}
public function get_tag()
{
$query = $this->db->order_by('tag_name', 'ASC')->get_where('tag', array('flag' => 1));
return $query->result_array();
}
public function get_selected_tag($article_id)
{
$query = $this->db
->select('tag.id, tag_name')
->join('article_tag', 'tag_id = tag.id')
->where(array('tag.flag' => 1, 'article_id' => $article_id))
->get('tag');
return $query->result_array();
}
public function insert()
{
$this->load->helper('upload');
$this->load->library('image_moo');
$image = file_upload('article_image', 'upload/article');
$this->image_moo->load($image['full_path']);
$this->image_moo->resize(924, 527)->save($image['path'] . '/' . $image['file_name'], TRUE);
$this->image_moo->resize_crop(100, 69)->save($image['path'] . '/thumb/' . $image['file_name']);
$this->image_moo->resize_crop(367, 232)->save($image['path'] . '/cover/' . $image['file_name']);
$insert_data = array(
'article_author'    => $this->session->admin_id,
'article_title'     => $this->input->post('article_title'),
'article_slug'      => url_title($this->input->post('article_title'), '-', TRUE),
'article_category'  => $this->input->post('article_category'),
'article_image'     => $image['file_name'],
'article_content'   => $this->input->post('article_content'),
'is_popup'          => $this->input->post('is_poup'),
'article_date'      => $this->input->post('article_date'),
);
$this->db->insert('article', $insert_data);
$article_id = $this->db->insert_id();
foreach ($this->input->post('article_tag') as $tag)
{
// Check apakah tag itu udah ada di database?
if (is_numeric($tag))
{
$tag_id = $tag;
}
else
{
$this->db->insert('tag', array('tag_name' => strtolower(trim($tag)), 'tag_slug' => url_title(trim($tag), '-', TRUE)));
$tag_id = $this->db->insert_id();
}
if ( ! $this->db->get_where('article_tag', array('article_id' => $article_id, 'tag_id' => $tag_id))->row_array())
{
$this->db->insert('article_tag', array('article_id' => $article_id, 'tag_id' => $tag_id));
}
}
}
public function update($id)
{
$this->load->helper('upload');
$this->load->library('image_moo');
$image = file_upload('article_image', 'upload/article');
$this->image_moo->load($image['full_path']);
$this->image_moo->resize(924, 527)->save($image['path'] . '/' . $image['file_name'], TRUE);
$this->image_moo->resize_crop(100, 69)->save($image['path'] . '/thumb/' . $image['file_name']);
$this->image_moo->resize_crop(367, 232)->save($image['path'] . '/cover/' . $image['file_name']);
$insert_data = array(
'article_author'    => $this->session->admin_id,
'article_title'     => $this->input->post('article_title'),
'article_slug'      => url_title($this->input->post('article_title'), '-', TRUE),
'article_category'  => $this->input->post('article_category'),
'is_popup'          => $this->input->post('is_popup'),
'article_content'   => $this->input->post('article_content'),
'article_date'      => $this->input->post('article_date'),
);
if ($image)
{
$insert_data['article_image'] = $image['file_name'];
}
$article_id = $id;
$this->db->where('id', $id);
$this->db->update('article', $insert_data);
$this->db->where('article_id', $id);
$this->db->delete('article_tag');
foreach ($this->input->post('article_tag') as $tag)
{
// Check apakah tag itu udah ada di database?
if (is_numeric($tag))
{
$tag_id = $tag;
}
else
{
$this->db->insert('tag', array('tag_name' => strtolower(trim($tag)), 'tag_slug' => url_title(trim($tag), '-', TRUE)));
$tag_id = $this->db->insert_id();
}
if ( ! $this->db->get_where('article_tag', array('article_id' => $article_id, 'tag_id' => $tag_id))->row_array())
{
$this->db->insert('article_tag', array('article_id' => $article_id, 'tag_id' => $tag_id));
}
}
}
}

伙计们,我该怎么办? 我做了备份,但它与升级后保持不变。谢谢。网址 (http://www.hidupseimbangku.com/)

第一。如果要升级CI版本,则必须逐个遵循升级指南。可能会有中断更改,您需要更正它们,您可以在此处找到本指南:

https://www.codeigniter.com/userguide3/installation/upgrading.html

我建议您回滚升级更改并重新开始一个接一个地执行。这并不难,只是很耗时。

您收到的错误可能与上传过程错误有关。什么是file_upload

我还建议您阅读此内容,以便正确上传文件。

最新更新