CodeIgniter Forums
Return False Blocking Multiple Messages - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Return False Blocking Multiple Messages (/showthread.php?tid=64372)



Return False Blocking Multiple Messages - wolfgang1983 - 02-13-2016

On my upload function I have a if in_array in my multiple upload. And sets multiple error messages.

My problem now if I put return FALSE; It will stop the multiple messages from showing and only set one message.

How can I solve this? Any ideas with examples thank you.


PHP Code:
public function upload($field 'userfile') {

 
   $allowed_extension explode('|'$this->allowed_types);

 
   if (empty($this->upload_path)) {
 
       $this->set_error('upload_path_not_set''upload_path_check');
 
        return FALSE;
 
   

 
   if (!realpath(FCPATH $this->upload_path)) {
 
       $this->set_error('upload_path_in_correct''location_check');
 
       return FALSE;
 
   

 
   if (!empty($this->files[$field]['name'][0])) {

 
       foreach ($this->files[$field]['name'] as $key => $value) {

 
           $this->file_name $this->files[$field]['name'][$key];

 
           $get_file_extension explode('.'$this->files[$field]['name'][$key]);
 
           $this->get_file_extension_end strtolower(end($get_file_extension));
 
               
            $array_1 
= array(
 
               $allowed_extension,
 
           );

 
           $array_2 = array(
 
               $get_file_extension[1],
 
           );
 
               
            if 
(!in_array($array_2$array_1)) {
 
                   
                $this
->set_error('file_extension_not_allowed''extension_check');

 
               return FALSE;
 
           }

 
       }

 
   }





RE: Return False Blocking Multiple Messages - skunkbad - 02-13-2016

Maybe something like this:


PHP Code:
/**
 * Array to hold error information about multiple uploads.
 * You can check this later to see what errors there were,
 * and not return FALSE inside the upload method.
 */
public $error_stack = array();

public function 
upload($field 'userfile') {

    $allowed_extension explode('|'$this->allowed_types);

    if (empty($this->upload_path)) {
        $this->set_error('upload_path_not_set''upload_path_check');

        // Put something in $this->error_stack ...
    

    if (!realpath(FCPATH $this->upload_path)) {
        $this->set_error('upload_path_in_correct''location_check');

        // Put something in $this->error_stack ...
    

    if (!empty($this->files[$field]['name'][0])){
        foreach ($this->files[$field]['name'] as $key => $value) {

            $this->file_name $this->files[$field]['name'][$key];

            $get_file_extension explode('.'$this->files[$field]['name'][$key]);
            $this->get_file_extension_end strtolower(end($get_file_extension));
                
            $array_1 
= array(
                $allowed_extension,
            );

            $array_2 = array(
                $get_file_extension[1],
            );
                
            
if (!in_array($array_2$array_1)) {
                    
                $this
->set_error('file_extension_not_allowed''extension_check');

                // Put something in $this->error_stack ...
            }

        }

    }





RE: Return False Blocking Multiple Messages - wolfgang1983 - 02-14-2016

(02-13-2016, 11:42 PM)skunkbad Wrote: Maybe something like this:


PHP Code:
/**
 * Array to hold error information about multiple uploads.
 * You can check this later to see what errors there were,
 * and not return FALSE inside the upload method.
 */
public $error_stack = array();

public function 
upload($field 'userfile') {

    $allowed_extension explode('|'$this->allowed_types);

    if (empty($this->upload_path)) {
        $this->set_error('upload_path_not_set''upload_path_check');

        // Put something in $this->error_stack ...
    

    if (!realpath(FCPATH $this->upload_path)) {
        $this->set_error('upload_path_in_correct''location_check');

        // Put something in $this->error_stack ...
    

    if (!empty($this->files[$field]['name'][0])){
        foreach ($this->files[$field]['name'] as $key => $value) {

            $this->file_name $this->files[$field]['name'][$key];

            $get_file_extension explode('.'$this->files[$field]['name'][$key]);
            $this->get_file_extension_end strtolower(end($get_file_extension));
                
            $array_1 
= array(
                $allowed_extension,
            );

            $array_2 = array(
                $get_file_extension[1],
            );
                
            
if (!in_array($array_2$array_1)) {
                    
                $this
->set_error('file_extension_not_allowed''extension_check');

                // Put something in $this->error_stack ...
            }

        }

    }



I need to use the return false. Not sure what I should

PHP Code:
$this->error_stack