Welcome Guest, Not a member yet? Register   Sign In
Multiple Image Uploading, and Thumb w/ set name.
#1

[eluser]Unknown[/eluser]
Hi

Before I get into the code, I have 6 file fields in my form. I'm not using CI's form helper, so they are simply.

Code:
<label for="icon">Icon</label> &lt;input type="file" name="icon" id="icon"&gt;
<label for="boxart">Box Art</label> &lt;input type="file" name="boxart" id="boxart"&gt;
<label for="screena">Screenshot A</label> &lt;input type="file" name="screena" id="screena"&gt;
<label for="screenb">Screenshot B</label> &lt;input type="file" name="screenb" id="screenb"&gt;
<label for="screenc">Screenshot C</label> &lt;input type="file" name="screenc" id="screenc"&gt;
<label for="screend">Screenshot D</label> &lt;input type="file" name="screend" id="screend"&gt;

My goal here is to upload these files with the following properties.
(I already have the clean name function working, which takes the field and removes all spaces and characters and replaces them with hyphens)

ICON:: Dimensions 32x32, Name - cleaned-name-ico.ext
BoxArt:: Dim - 1200x1200, Name - cleaned-name-box.ext
Screenshots: Dim - 1920x1200, Name - cleaned-name-sA-D.ext

Right now I'm trying to use bits and pieces of code that was posted here. Mostly from Latavish's thread.

My issue is that I'm managing to get ONE file to upload and thumbnail. With my desired name, but it normally either turns out 'clean-name-s.ext' or 'clean-name-sa(sometimes d).ext' - the function won't loop through and add a different letter per entry.

Here's my controller.
Code:
// Validation - If successful...
            else        
            {    
#
                $this->load->model('Games_model');
                foreach ( $_FILES as $key => $value )
                {
                    
                    $config['upload_path'] = './uploads/temp/';
                    $config['allowed_types'] = 'gif|jpg|png';
                    $config['max_size'] = '2048';
                    $config['max_width'] = '1920';
                    $config['max_height'] = '1200';
                    
                    if ( ! empty($key['name']) )
                    {
                        $this->upload->initialize($config);
                        if ( ! $this->upload->do_upload($key) )
                        {
                            $errors[] = $this->upload->display_errors();
                        }
                        else
                        {
                            $this->Games_model->process_image();
                        }
                    }
                }
#

and my Model
Code:
function process_image()
    {
        $uploads = array($this->upload->data());    
        
        $cleaned = clean_name($this->input->post('gamename'));
            
        foreach( $uploads as $key => $value )
        {    
            $imagename = $cleaned.'-s'.$value['file_ext'];
            $config['image_library'] = 'GD2';
            $config['source_image'] = $value['full_path'];
            $config['create_thumb'] = TRUE;
            $config['thumb_marker'] = '-tn';
            $config['master_dim'] = 'width';
            $config['quality'] = 90;
            $config['maintain_ratio'] = TRUE;
            $config['width'] = 175;
            $config['height'] = 175;
            $config['new_image'] = './uploads/games/images/'.$imagename;
                        
            $this->image_lib->initialize($config);
            
            $this->image_lib->resize();

            rename($value['full_path'], './uploads/games/images/'.$imagename);
        }
                
        
    }

So essentially, I need to pin-point the file fields some how - and I want to append the different letter to each screenshot.

Any ideas on how I can achieve this?

------

Also while I'm here and posting, to avoid posting 15 different threads.
In my validation rules I've placed
Code:
$this->form_validation->set_rules('screena', 'screenshot a', 'required');
and despite a file being submitted, it kept returning false. Is there something else I need to do for validation of file fields?




Theme © iAndrew 2016 - Forum software by © MyBB