Welcome Guest, Not a member yet? Register   Sign In
Single, Multiple and Multiple array upload library
#21

[eluser]Av007[/eluser]
Easy way to multiple files upload

part of view
Code:
<input type="file" name="image[]" />
part of controller content
Code:
<?php
    // Image
    $config['upload_path'] = $path.'images/';
    $config['allowed_types'] = 'gif|jpg|png';
    $config['file_name'] = 'screenshot';
    $config['max_size'] = '1024';
    $config['overwrite'] = true;

    $this->load->library('upload', $config);
    // RE-SERIALIZE $_FILES ARRAY
    foreach($_FILES['image'] as $key => $file)
    {
        $i = 0;
        foreach ($file as $item)
        {
            $data[$i][$key] = $item;
            $i++;
        }
    }
    // END RE-SERIALIZE
    //print_r($_FILES);die; // see the real income data
    //print_r($data); die; // serialized data
    $file = ''; // reset
    $_FILES = $data; // re-declarate
    for($j=0;$j<count($data);$j++)
    {
        $config['file_name'] = 'image_'.$j;
        $this->upload->initialize($config);
        if($this->upload->do_upload($j)){
            $file = $this->upload->data();
        }
    }
CodeIgniter v.1.7.3
#22

[eluser]Krasser[/eluser]
The filetype you are attempting to upload is not allowed.

Code:
$config['allowed_types'] = 'gif|jpg|png';

Im upload png files, why coming this kind error have i missed something?
#23

[eluser]Av007[/eluser]
Check function from system/libraries/Upload.php
Code:
/**
     * Verify that the filetype is allowed
     *
     * @access    public
     * @return    bool
     */    
    function is_allowed_filetype() {
        if (count($this->allowed_types) == 0 OR ! is_array($this->allowed_types))
        {
            $this->set_error('upload_no_file_types');
            return FALSE;
        }

        if (in_array("*", $this->allowed_types))
        {
            return TRUE;
        }

        $image_types = array('gif', 'jpg', 'jpeg', 'png', 'jpe');

        foreach ($this->allowed_types as $val)
        {
            $mime = $this->mimes_types(strtolower($val));

            // Images get some additional checks
            if (in_array($val, $image_types))
            {
                if (getimagesize($this->file_temp) === FALSE)
                {
                    return FALSE;
                }
            }

            if (is_array($mime))
            {
                if (in_array($this->file_type, $mime, TRUE))
                {
                    return TRUE;
                }
            }
            else
            {
                if ($mime == $this->file_type)
                {
                    return TRUE;
                }
            }
        }

        return FALSE;
    }
#24

[eluser]Krasser[/eluser]
Smile You idea is not work for me! but im learn some from you! Im settled! Thank you for helping!
#25

[eluser]Unknown[/eluser]
Yes - that's ok
#26

[eluser]porquero[/eluser]
This helper make easy use array names for upload files with array names.

Example:

In view
Code:
&lt;form...
&lt;input type="file" name="files[]">
&lt;input type="file" name="files[]"&gt;
...
&lt;/form&gt;

In controller
Code:
load->helper('upload');
multifile_array();
foreach ($_FILES as $file => $file_data)
  $this->upload->do_upload($file);

Download:
http://porquero.blogspot.com/2012/05/cod...pload.html
#27

[eluser]Unknown[/eluser]
how it will going to connect to the database? the multiple upload.
#28

[eluser]porquero[/eluser]
[quote author="iamjnn" date="1344913219"]how it will going to connect to the database? the multiple upload.[/quote]

You should use upload class:

http://ellislab.com/codeigniter/user-gui...ading.html




Theme © iAndrew 2016 - Forum software by © MyBB