将变量发送到$ this-> session-> set_flashdata

时间:2019-05-17 11:14:15

标签: 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'; 
     $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();

它显示以下内容:

  

您尝试上传的图片不符合允许的大小   尺寸。

1 个答案:

答案 0 :(得分:0)

**'allowHtml': true** property 


$scope.orgChartObj = {
  "type": "OrgChart",
//   "displayed": false,
  "data": {
    "cols" : [
          {"label": "id", "pattern": "", "type": "string"},
          {"label": "manager", "pattern": "", "type": "string"}
      ],
    "rows" : []
  },
  "formatters": {},
  "view": {},
  "options": {
       'allowHtml': true
 }
}; 

view.php

$this->session->set_flashdata('item', 'Successfully uploaded');

选中此链接

https://i.stack.imgur.com/MkKvZ.png