Welcome Guest, Not a member yet? Register   Sign In
Latavish's Multiple Image Upload with Thumbnail Generation
#11

[eluser]Leon Stafford[/eluser]
I've just used this with ever slightly modified default code from the User Guide to enable multi-file uploads. It produces multiple views of the results too.

Note: Check your uploads folder path if different than mine. Also, if rewriting your URLs, add the upload folder name to your .htaccess file or you may get errors.


Here is my upload.php file:

Code:
<?php

class Upload extends Controller {
    
    function Upload()
    {
        parent::Controller();
        $this->load->helper(array('form', 'url','html'));
    }
    
    function index()
    {    
        $this->load->view('upload_form', array('error' => ' ' ));
    }

    function do_upload()
    {
        $config['upload_path'] = './uploads/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size']    = '1000';
        
        $this->load->library('upload');
    //
     foreach($_FILES as $key => $value)
        {
            if( ! empty($key['name']))
            {
                $this->upload->initialize($config);
        
                if ( ! $this->upload->do_upload($key))
                {
                    $errors[] = $this->upload->display_errors();
                    
                    $this->load->view('upload_form', $error);
                }    
                else
                {
                    $data[$key] = array('upload_data' => $this->upload->data());
            
                    $this->load->view('upload_success', $data[$key]);
                    

                }
             }
        
        }
    //
    
        
    }    
}
?>

Here is my upload_form.php file:

Code:
<html>
<head>
<title>Upload Form</title>
</head>
<body>

<?php echo $error;?>

<?php echo form_open_multipart('upload/do_upload');?>

<input type="file" name="userfile" size="20" />
<br /><br />
&lt;input type="file" name="userfile2" size="20" /&gt;
<br /><br />
&lt;input type="file" name="userfile3" size="20" /&gt;
<br /><br />
&lt;input type="file" name="userfile4" size="20" /&gt;
<br /><br />
<br /><br />

&lt;input type="submit" value="upload" /&gt;

&lt;/form&gt;

&lt;/body&gt;
&lt;/html&gt;

Here is my upload_success.php file:

Code:
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Upload Form&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;

<h3>Your file was successfully uploaded!</h3>

<ul>
&lt;?php foreach($upload_data as $item => $value):?&gt;
<li>&lt;?php echo $item;?&gt;: &lt;?php echo $value;?&gt;</li>
&lt;?php endforeach; ?&gt;
</ul>
&lt;? if ($upload_data['file_name']):?&gt;

&lt;? echo img('uploads/'.$upload_data['file_name']);?&gt;

&lt;? endif;?&gt;

<p>&lt;?php echo anchor('upload', 'Upload Another File!'); ?&gt;</p>

&lt;/body&gt;
&lt;/html&gt;


Messages In This Thread
Latavish's Multiple Image Upload with Thumbnail Generation - by El Forum - 02-06-2009, 10:37 PM



Theme © iAndrew 2016 - Forum software by © MyBB