【发布时间】:2019-05-17 11:14:14
【问题描述】:
我正在尝试上传图片,并想在以下代码中获取 set_flashdata 中的错误,无法将错误消息作为变量发送。
public function update_data($id)
{
$config['upload_path'] = "./school_folder/users_picture";
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '2048';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$config['file_name'] = $id;
$config['encrypt_name'] = false;
$this->load->library('upload', $config);
$this->upload->overwrite = true;
if ( ! $this->upload->do_upload('image'))
{ // in case of fuilure
// the following portion of code don't show the error message
$error = $this->upload->display_errors();
$this->session->set_flashdata('item',$error );
redirect('index.php/Users/students_edit/'.$id);
}
else // in case of success
{
$this->session->set_flashdata('item', 'Successfully uploaded' );
redirect('index.php/Users/students_edit/'.$id);
}
这里是 $error 的调试:
$error = $this->upload->display_errors();
echo $error;
die();
它显示以下内容:
您尝试上传的图片不符合允许的范围 尺寸。
【问题讨论】:
-
那么你的问题是什么?
-
我想在重定向到视图时显示错误消息。
-
那么您是否检查了 $error 包含的内容,通过制作调试输出并注释掉重定向...?
-
是的,它有这个错误:您尝试上传的图片不符合允许的尺寸。
-
请编辑您的问题并添加用于显示错误的代码,因为这就是您要询问的内容。
标签: php codeigniter session