![]() |
Problem with display_errors - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Problem with display_errors (/showthread.php?tid=16619) Pages:
1
2
|
Problem with display_errors - El Forum - 03-12-2009 [eluser]tim1965[/eluser] Hi I am hoping someone could help. I am having a problem in getting display_errors to output to my view. My view keeps erroring with an "undefined variable" for $data. I am assuming this is because display_errors is tryng to pass a string for each upload rather than an array. I am obviously doing something incorrectly when trying creating or trying to pass the array across to the view. I have tried many of the examples in the forum but cannot seem to get it to work correctly. My controller $data['error'] = array ('value' =>$this->upload->display_errors()); $this->load->view('propreg/f_propreg3_multifileupload_v1', $data); My view <?php foreach($error as $key => $v) : ?> <?php echo $v; ?> <?php endforeach; ?> The created array for $error looks like Quote:array(1) { ["error"]=> array(1) { ["value"]=> string(43) " You did not select a file to upload. " } } No files selectedarray(1) { ["error"]=> array(1) { ["value"]=> string(43) " You did not select a file to upload. " } } No files selectedarray(1) { ["error"]=> array(1) { ["value"]=> string(43) " You did not select a file to upload. " } } No files selectedarray(1) { ["error"]=> array(1) { ["value"]=> string(43) " You did not select a file to upload. " } } No files selectedarray(1) { ["error"]=> array(1) { ["value"]=> string(43) " You did not select a file to upload. " } } No files selectedarray(1) { ["error"]=> array(1) { ["value"]=> string(43) " You did not select a file to upload. " } } No files selectedarray(1) { ["error"]=> array(1) { ["value"]=> string(43) " You did not select a file to upload. " } } No files selected You did not select a file to upload. Quote: I am hoping therefore that someone can post an example that is working for them correctly. As i said i have tried many of the examples on the forum but cannot get any to work correctly for me. All seem to drop out with undefined variable. If i can use an example that definitively works for someone, then i can take the array creation and passing out of the equation at the problem. Many thanks in advance. Problem with display_errors - El Forum - 03-12-2009 [eluser]jacobc[/eluser] I guess you are trying to do a multiple upload... If you want an array of any errors, you should probably use something like: Code: $data['errors'][] = $this->upload->display_errors(); And initialize it before you start adding errors... Code: $data['errors'] = array(); Then you can loop through them how you like... at the moment you're simply overwriting the array... There is no need to separate the key and value in this case either... simply do: Code: <?php foreach($errors as $error) : ?> Problem with display_errors - El Forum - 03-12-2009 [eluser]tim1965[/eluser] jacobc Thanks for the reply. I tried your solution, but i get 2 php errors Quote:Message: Undefined variable: errors Quote:and Quote:Invalid argument supplied for foreach() Quote:These are the errors i have been getting. Is the solution you supplied working correctly for you ? Problem with display_errors - El Forum - 03-12-2009 [eluser]jacobc[/eluser] maybe post the code from you controller... Make sure you are using Code: $data['errors'] Code: $data['error'] If that's not the problem. Just before you call your view do Code: print_r($data) Problem with display_errors - El Forum - 03-12-2009 [eluser]tim1965[/eluser] I am correctly calling ['errors'] results of print Quote:Array ( [errors] => Array ( ) ) No files selectedArray ( [errors] => Array ( ) ) No files selectedArray ( [errors] => Array ( ) ) No files selectedArray ( [errors] => Array ( ) ) No files selectedArray ( [errors] => Array ( ) ) No files selectedArray ( [errors] => Array ( ) ) No files selectedArray ( [errors] => Array ( ) ) No files selected Quote: Problem with display_errors - El Forum - 03-12-2009 [eluser]tim1965[/eluser] controller code function picupload() { //Load Model $this->load->model('Process_image'); //get property id to create directory for pictures and thumbs $prop = $this->session->userdata('propid'); $propid = $prop['prop_id'][0]; if (isset($_POST) && count($_POST) >0 ) //{ //create directories for upload based on property id $prop = $this->session->userdata('propid'); $propid = $prop['prop_id'][0]; $mypath = './system/pictures/'.$propid; $main_pic = './system/pictures/'.$propid.'/pictures/'; $thumb_path = './system/pictures/'.$propid.'/thumbs/'; if (!is_dir($mypath)) { mkdir($mypath,0777,TRUE); } if (!is_dir($main_pic)) { mkdir($main_pic,0777,TRUE); } if (!is_dir($thumb_path)) { mkdir($thumb_path,0777,TRUE); } $this->load->library('upload'); //$mypath="C:\\wamp\\www\\ci\\system\\pictures\\$propid"; $config['upload_path'] = './system/uploads/'; $config['allowed_types'] = 'gif|jpg|png'; $config['max_size'] = '2048'; //2 meg foreach($_FILES as $key => $value) { //changed value from key if( ! empty($key['name'])) { $this->upload->initialize($config); if ( ! $this->upload->do_upload($key['name'])) { //$data['error'] = array ('value' =>$this->upload->display_errors()); $data['errors'][] = $this->upload->display_errors(); $data['errors'] = array(); print_r($data); $this->load->view('propreg/f_propreg3_multifileupload_v1', $data); //Upload Form } else { $this->load->model('Process_image'); $this->Process_image->process_pic(); } } //} } // $this->load->view('propreg/f_propreg3_multifileupload_v1'); redirect('propreg/f_propreg3_multifileupload_v1', $data); //Picture Upload View //} }//end picupload }//end controller Problem with display_errors - El Forum - 03-12-2009 [eluser]jacobc[/eluser] Oh are you looping through the files and calling the view within the loop? In that case your original code is ok, but in your view all you need to do is Code: <?php echo $error?> I am only making assumptions about what you are doing in your controller though. It would be helpful if you post the code from your action in the controller. Problem with display_errors - El Forum - 03-12-2009 [eluser]jacobc[/eluser] You are passing the wrong argument to the do_upload function I'm quite certain... you want to pass it the $key value, not $key['name']... try Code: foreach($_FILES as $key => $value) { Problem with display_errors - El Forum - 03-12-2009 [eluser]tim1965[/eluser] Hi I tried that and it will display but i still get and undefined variable error for $error. I have posted the controller above. Appreciate your help. Any suggestions ?? Problem with display_errors - El Forum - 03-12-2009 [eluser]tim1965[/eluser] Ok sorry we seem to be crossing posts. If i use value instead of name should i go back to oyur original suggestion of $data['errors'][] = $this->upload->display_errors(); $data['errors'] = array(); and run that again ?? |