Welcome Guest, Not a member yet? Register   Sign In
Return False Blocking Multiple Messages
#1

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;
 
           }

 
       }

 
   }


There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply
#2

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 ...
            }

        }

    }


Reply
#3

(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 
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB