首页 > 解决方案 > CodeIgniter 突然无法上传图片并说不能为空

问题描述

问候大家,特别是 CodeIgniter 开发人员的高级人员。

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

错误号:1048 列“article_image”不能为空

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

这是我的文章模型

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/ )

标签: codeigniter-3

解决方案


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

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

我建议您回滚升级更改并重新开始一项一项。这并不难,只是耗时。

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

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


推荐阅读