Welcome Guest, Not a member yet? Register   Sign In
Problem with display_errors
#1

[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.
#2

[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();
That will add new element to the array each time.

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) : ?>
<?php echo $error; ?>
<?php endforeach; ?>
#3

[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 ?
#4

[eluser]jacobc[/eluser]
maybe post the code from you controller...

Make sure you are using
Code:
$data['errors']
Not
Code:
$data['error']

If that's not the problem.
Just before you call your view do
Code:
print_r($data)
And post the results.
#5

[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:
#6

[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
#7

[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.
#8

[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) {
    $this->upload->initialize($config);
    if ( ! $this->upload->do_upload($key)) {
        //$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();

    }
}
#9

[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 ??
#10

[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 ??




Theme © iAndrew 2016 - Forum software by © MyBB