【发布时间】:2018-09-26 02:24:16
【问题描述】:
我有一个如下的模型函数。当我点击提交时,所有数据都保存在数据库中,但图像字段值存储为Array,Array,Array。
如何解决这个问题?我是 PHP 和 CodeIgniter 的初学者。
public function create_post($post_image){
$slug = url_title($this->input->post('title'));
$image = implode(',',$post_image);
$data = array(
'title' => $this->input->post('title'),
'slug' => $slug,
'body' => $this->input->post('body'),
'category_id' => $this->input->post('category_id'),
'user_id' => $this->session->userdata('user_id'),
'post_image' => $image
);
return $this->db->insert('posts', $data);
}
【问题讨论】:
-
要保存图片名称吗?
-
@Harun Anwar,注释所有代码并添加
print_r($post_image)并查看显示的内容...然后复制这些代码并将其添加到此处。所以我们可以为您找到解决方案.. -
做一些调试。找出
$post_image的值是什么。 -
$post_image是一个$_FILES数组显然。 -
我在 print_r($post_image); 之后得到了关注Array ( [images] => Array ( [name] => Array ( [0] => img.jpg ) [type] => Array ( [0] => image/jpeg ) [tmp_name] => Array ( [0 ] => D:\xampp\tmp\php7052.tmp ) [错误] => 数组 ( [0] => 0 ) [大小] => 数组 ( [0] => 622030 ) ) )
标签: php database codeigniter implode