[eluser]textnotspeech[/eluser]
When using the File Uploading Class in one of my custom library classes I seem to be getting only one error even if more errors exist. In other words, I'm expecting an array and only getting a string returned from the "display_errors()" function.
Inside my class I have a function that utilizes the File Uploading Class and I'm stuffing an array to return to the controller that contains a key value pair for the success state and then returns either an array of the file info or the errors. I am assuming that the "display_errors()" function returns an array of each violation of config rules but the User Guide is not specific.
Here's my function:
Code:
<?
if (!defined('BASEPATH')) exit('No direct script access allowed');
class Imageator
{
function move_temp()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|jpeg|png';
$config['max_size'] = '1';
$config['max_width'] = '1';
$config['max_height'] = '2250';
$config['overwrite'] = TRUE;
$CI =& get_instance();
$CI->load->library('upload', $config);
if (!$CI->upload->do_upload("image"))
{
$data['errors'] = array('errors' => $CI->upload->display_errors('', ''));
$data['success'] = FALSE;
}
else
{
$data['upload_data'] = $CI->upload->data();
$data['success'] = TRUE;
}
return $data;
}
}
?>
Inside the Controller:
Code:
function publish()
{
$data['upload'] = $this->imageator->move_temp();
$this->load->view('home_content/v_upload', $data);
}
And the view:
Code:
<? if ($upload['success']): ?>
<p>I think it worked. Check the folder</p>
<ul>
<? foreach($upload['upload_data'] as $item => $value): ?>
<li><?= $item; ?>: <?= $value; ?></li>
<? endforeach; ?>
</ul>
<? else: ?>
<p>What else is new?</p>
<ul>
<? foreach($upload['errors'] as $item => $value): ?>
<li><?= $item; ?>: <?= $value; ?></li>
<? endforeach; ?>
</ul>
<? endif ?>
I get this:
Code:
<ul>
<li>errors: The file you are attempting to upload is larger than the permitted size</li>
</ul>
It works but I only get 1 error instead of 2 (the image I am uploading is larger than 1k and also wider than 1 px). The view and controller at this point are just tests of the "move_temp()" function and I'm a bit confused as to how this class works. Any suggestions?