0

我正在尝试使用 CodeIgners Upload 类从成功上传的图像(file_name、image_size_str)中获取信息。我想将此选择数据放入一个新数组中,以便我可以存储在数据库表中。当使用 foreach 循环数据,尝试使用 array_push 放入新数组时,代码失败。我必须失败评论。

function do_upload(){
$dbImgInfoStore = array();  
$this->load->model('upload_model');
$config['upload_path']='./uploads/';
$config['allowed_types']='gif|jpg|png';
$config['max_size']='10000'; //etc, etc
$this->load->library('upload', $config);
if(!$this->upload->do_upload()){
    $error = array('error'=>$this->upload->display_errors());
    $this->load->view('upload_form',$error);
} else {
    $data = array('upload_data'=>$this->upload->data());
    // NOT WORKING EITHER! 
    foreach($data as $key=>$value) {
        if($key == 'image_size_str') {
            array_push($dbImgInfoStore, $dbImgInfoStore['image_size_str']=$value);
        } elseif ($key == 'file_name') {
            array_push($dbImgInfoStore, $dbImgInfoStore['file_name']=$value);
        }
    } 
    $this->load->view('upload_success', $data);

}
}

奇怪的是,当发送到新页面时

$this->load->view('upload_success', $data);

我能够完全按照我之前尝试做的几行来做。

4

1 回答 1

2

您需要$data['upload_data']foreach循环中访问:

foreach($data['upload_data'] as $key => $value) {
    if($key == 'image_size_str') {
       $dbImgInfoStore['image_size_str'] = $value;
    } 
    elseif ($key == 'file_name') {
       $dbImgInfoStore['file_name'] = $value;
    }
} 
于 2013-11-15T01:09:07.120 回答