Welcome Guest, Not a member yet? Register   Sign In
Invalid argument supplied for foreach()
#4

[eluser]SaSa[/eluser]
this is function go_uploadSadPlease help me...)
Code:
function go_upload($field = 'userfile') {
        $CI =& get_instance();
        // Is $_FILES[$field] set? If not, no reason to continue.
        if ( ! isset($_FILES[$field]['name'][0]))
        {
            $CI->upload->set_error('upload_no_file_selected');
            return FALSE;
        } else
        {
            $num_files = count($_FILES[$field]['name']) -1;
            $file_list = array();
            $error_hold = array();
            $error_upload = FALSE;
        }
        if ( ! $CI->upload->validate_upload_path())
        {
            return FALSE;
        }
        for ($i=0; $i < $num_files; $i++) {
            $error_hold[$i] = FALSE;
            if ( ! is_uploaded_file($_FILES[$field]['tmp_name'][$i]))
            {
                $error = ( ! isset($_FILES[$field]['error'][$i])) ? 4 : $_FILES[$field]['error'][$i];
                switch($error)
                {
                    case 1:  // UPLOAD_ERR_INI_SIZE
                        $error_hold[$i] = 'upload_file_exceeds_limit';
                        break;
                    case 2: // UPLOAD_ERR_FORM_SIZE
                        $error_hold[$i] = 'upload_file_exceeds_form_limit';
                        break;
                    case 3: // UPLOAD_ERR_PARTIAL
                       $error_hold[$i] = 'upload_file_partial';
                        break;
                    case 4: // UPLOAD_ERR_NO_FILE
                       $error_hold[$i] = 'upload_no_file_selected';
                        break;
                    case 6: // UPLOAD_ERR_NO_TMP_DIR
                        $error_hold[$i] = 'upload_no_temp_directory';
                        break;
                    case 7: // UPLOAD_ERR_CANT_WRITE
                        $error_hold[$i] = 'upload_unable_to_write_file';
                        break;
                    case 8: // UPLOAD_ERR_EXTENSION
                        $error_hold[$i] = 'upload_stopped_by_extension';
                        break;
                    default :
                        $error_hold[$i] = 'upload_no_file_selected';
                        break;
                }
                return FALSE;
            }
            $CI->upload->file_temp = $_FILES[$field]['tmp_name'][$i];
        $CI->upload->file_name = $_FILES[$field]['name'][$i];
            $CI->upload->file_size = $_FILES[$field]['size'][$i];        
            $CI->upload->file_type = preg_replace("/^(.+?);.*$/", "\\1", $_FILES[$field]['type'][$i]);
            $CI->upload->file_type = strtolower($CI->upload->file_type);
            $CI->upload->file_ext  = $CI->upload->get_extension($_FILES[$field]['name'][$i]);            
            if ($CI->upload->file_size > 0)
            {
                $CI->upload->file_size = round($CI->upload->file_size/1024, 2);
            }
            if ( ! $CI->upload->is_allowed_filetype())
            {
                $error_hold[$i] = 'upload_invalid_filetype';
            }
            if ( ! $CI->upload->is_allowed_filesize())
            {
                $error_hold[$i] = 'upload_invalid_filesize';
            }
            if ( ! $CI->upload->is_allowed_dimensions())
            {
                $error_hold[$i] = 'upload_invalid_dimensions';
            }
            $CI->upload->file_name = $CI->upload->clean_file_name($CI->upload->file_name);
            if ($CI->upload->remove_spaces == TRUE)
            {
                $CI->upload->file_name = preg_replace("/\s+/", "_", $CI->upload->file_name);
            }
            $CI->upload->orig_name = $CI->upload->file_name;

            if ($CI->upload->overwrite == FALSE)
            {
                $CI->upload->file_name = $CI->upload->set_filename($CI->upload->upload_path, $CI->upload->file_name);
                
                if ($CI->upload->file_name === FALSE)
                {
                    $error_hold[$i] = TRUE;
                }
            }
            if ( ! @copy($CI->upload->file_temp, $CI->upload->upload_path.$CI->upload->file_name))
            {
                if ( ! @move_uploaded_file($CI->upload->file_temp, $CI->upload->upload_path.$CI->upload->file_name))
                {
                     $error_hold[$i] = 'upload_destination_error';
                }
            }
            if ($CI->upload->xss_clean == TRUE)
            {
                $CI->upload->do_xss_clean();
            }
            
            if ($error_hold[$i]) {
                $error_upload = TRUE;
            } else {
                if ($imageVar = $this->multiple_image_properties($CI->upload->upload_path.$CI->upload->file_name)) {

                    $file_list[] = array(
                            'name' => $CI->upload->file_name,
                            'file' => $CI->upload->upload_path.$CI->upload->file_name,
                            'size' => $CI->upload->file_size,
                            'ext' => $CI->upload->file_ext,
                            'image_type' => $imageVar->image_type,
                            'height' => $imageVar->height,
                            'width' => $imageVar->width
                            );
                } else {
                    $file_list[] = array(
                            'name' => $CI->upload->file_name,
                            'file' => $CI->upload->upload_path.$CI->upload->file_name,
                            'size' => $CI->upload->file_size,
                            'type' => $CI->upload->file_type,
                            'ext' => $CI->upload->file_ext,
                            );
                }
            }      
        if ($error_upload) {
            $this->set_error($error_hold);
            return FALSE;
        } else {
            return $file_list;
        }    
    }


Messages In This Thread
Invalid argument supplied for foreach() - by El Forum - 07-27-2011, 04:56 AM
Invalid argument supplied for foreach() - by El Forum - 07-27-2011, 05:07 AM
Invalid argument supplied for foreach() - by El Forum - 07-27-2011, 09:22 AM
Invalid argument supplied for foreach() - by El Forum - 07-27-2011, 02:25 PM
Invalid argument supplied for foreach() - by El Forum - 07-27-2011, 03:36 PM
Invalid argument supplied for foreach() - by El Forum - 07-27-2011, 04:15 PM
Invalid argument supplied for foreach() - by El Forum - 07-28-2011, 02:53 AM
Invalid argument supplied for foreach() - by El Forum - 07-28-2011, 05:36 AM
Invalid argument supplied for foreach() - by El Forum - 07-28-2011, 06:26 AM
Invalid argument supplied for foreach() - by El Forum - 07-28-2011, 07:42 AM
Invalid argument supplied for foreach() - by El Forum - 07-28-2011, 08:28 AM
Invalid argument supplied for foreach() - by El Forum - 07-28-2011, 08:34 AM
Invalid argument supplied for foreach() - by El Forum - 07-28-2011, 09:39 AM
Invalid argument supplied for foreach() - by El Forum - 07-28-2011, 12:03 PM
Invalid argument supplied for foreach() - by El Forum - 07-28-2011, 12:05 PM
Invalid argument supplied for foreach() - by El Forum - 07-29-2011, 12:49 AM
Invalid argument supplied for foreach() - by El Forum - 07-29-2011, 07:34 AM



Theme © iAndrew 2016 - Forum software by © MyBB