Php 将变量发送到$this->;会话->;设置flashdata
我正在尝试上载图像,并希望捕获set_flashdata中的错误,在下面的代码中,无法将错误消息作为变量发送Php 将变量发送到$this->;会话->;设置flashdata,php,codeigniter,session,Php,Codeigniter,Session,我正在尝试上载图像,并希望捕获set_flashdata中的错误,在下面的代码中,无法将错误消息作为变量发送 public function update_data($id) { $config['upload_path'] = "./school_folder/users_picture"; $config['allowed_types'] = 'gif|jpg|png'; $config['max_size'] = '2048'; $con
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();
它显示以下内容:
您尝试上载的图像不符合允许的格式
尺寸
view.php
<?php if ($this->session->flashdata('msg')) { ?>
<div id="mydiv" class="alert alert-success"><?= $this->session->flashdata('category_success') ?>
<?php
echo $this->session->flashdata('msg');
?>
</div>
<?php } ?>
检查此链接
那么您的问题是什么?我想在重定向到查看时显示错误消息。那么您是否检查了$error包含的内容,通过进行调试输出并注释重定向…?是的,它有此错误:您尝试上载的图像不符合允许的维度。请编辑您的问题并添加显示错误的代码,因为这就是您要问的问题。$this->session->set_flashdata('item','that somting erre');重定向('index.php/Users/students_edit/'。$id);这将显示消息。$error=$this->upload->display_errors()$此->会话->设置\u flashdata('item',$error);重定向('index.php/Users/students_edit/'。$id);但这并没有显示变量$errorset_flashdata('item',$error)中的内容。我没有使用2个不同的变量,这可能是打字错误。
<?php if ($this->session->flashdata('msg')) { ?>
<div id="mydiv" class="alert alert-success"><?= $this->session->flashdata('category_success') ?>
<?php
echo $this->session->flashdata('msg');
?>
</div>
<?php } ?>