2

画像アップローダーの問題で立ち往生しています。正常に動作する画像アップローダーを作成しましたが、それらも編集する必要があります。必要な画像を追加すると、db 列は正しく更新されますが、画像を変更せずにそのままにしておくと、「列 '画像' を null にすることはできません」というエラーが表示されます。

これは、更新セクションのコードです。

else if ($type == 'update')
{

    if($this->input->post('image')) {
        $fdata = $this->savenew();
        $data['image'] = $fdata['upload_data']['file_name'];

    } else {
         $data['image'] = $this->input->post('current_image');


    }

    $return = $this->add_radio_model->update($id, $data);
}

あまり明確でなかったらごめんなさい

編集:

     private function savenew(){                

     $config['upload_path'] = './assets/'; //Make SURE that you chmod this directory to 777!
     $config['allowed_types'] = 'gif|jpg|png';
     $config['max_size']    = '0'; // 0 = no limit on file size (this also depends on your PHP configuration)
     $config['remove_spaces']=TRUE; //Remove spaces from the file name

     $this->load->library('upload', $config);

    if ( ! $this->upload->do_upload('image'))
    {
            $data['error']= array('error' => $this->upload->display_errors());
            log_message('error',$data['error']);
            }
            else
                {
                $data = array('upload_data' => $this->upload->data());

                }
        return $data;
    }
4

1 に答える 1

2

コメント スレッドによると、ここでコードを変更する必要があります

else if ($type == 'update')
{
    if($this->input->post('image')) {
        $fdata = $this->savenew();
        // first always set current image  
        $data['image'] = $this->input->post('current_image');
        // second check if new image added if yes, then update otherwise keep original image as it is
        if(isset($fdata['upload_data'])){
           $data['image'] = $fdata['upload_data']['file_name'];
        }
    }
    $return = $this->add_radio_model->update($id, $data);
}

2 番目の問題の場合:A PHP Error was encountered Severity: Notice Message: Array to string conversion Filename: libraries/Log.php Line Number: 99

変化する:

$data['error']= array('error' => $this->upload->display_errors());
log_message('error',$data['error']);

log_message('error',(string) $this->upload->display_errors());
于 2012-11-04T14:29:13.363 に答える