Welcome Guest, Not a member yet? Register   Sign In
Mutiple Uploads Working!! But Files NOT being Process! Can someone help?
#1

[eluser]Latavish[/eluser]
Hi Guys,

I have read and re-read thru the forum about this issue but i can't seem to locate an answer anywhere. I'll try my best to break this down and explain exactly what im trying to do. So I hope you CI gurus can understand me. :-)

From you guys here at the CI forums I have figured out how to upload multiple files via CI and that seems to work fine. The files are uploaded to my /uploads/ directory which is just a temp directory till i get the files processed, meaning resized and moved to the users storage folder.

Now here is my problem that I just can't seem to figure out. When I upload more then 1 file at a time, it only processes the 1st FILE and not the other files. Dont get me wrong, all files are uploading but when its not looping thru the (i'm assuming) the $_files array to process not just the 1st, but all files. You'll notice the "$this->Process_image->process();" which does the processing. All this is suppose to do is to move the uploaded files from the uploads folder to the users actually storage folder and adds a random code to the org file to prevent the same file name can't be uploaded and overwritten. Like i stated everything works perfect for the 1st uploaded file but any other files are not being processed.

Now I had the understanding that this would loop thru the files array and process each files just as it loops thru and uploads each file. But i guess thats just not the case.

Here is the Upload Controller

Code:
function picupload()
    {
        //Load Model
        $this->load->model('Process_image');
        
        $config['upload_path'] = './uploads/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size']    = '2048'; //2 meg


        $this->load->library('upload');
        
        $keys = array_keys($_FILES);
        $errors = array();
        $uploads = array();
        
        //foreach($_FILES as $key => $value)
        for( $i=0; $i<8; $i++ ){
            
            $this->upload->initialize($config);
            $field_name = "imagefile".$i;
            
            if(!empty($$field_name['temp_name']))
            {
            
            
                if ( ! $this->upload->do_upload($field_name))
                {
                    $errors[] = $this->upload->display_errors();
                    
                }    
                else
                {
                    //$uploads[] = $this->upload->data();
                    $this->Process_image->process();            
                }
         }
        }


        
    }

And Here is the Model

Code:
function process()
    {            
                    
        //Get File Data Info
        $uploads = $this->upload->data();
        
        //Generate code
        $code = generate_code(7);
            
            //Move File to User Folder Thumbnail
            
            $config['image_library'] = 'GD2';
            $config['source_image'] = $uploads['full_path'];
            //$config['create_thumb'] = TRUE;
            //$config['master_dim'] = 'height';
            //$config['quality'] = 100;
            $config['new_image'] = $this->config->item('userfiles').$this->session->userdata('username').'/pictures/'.$code.$uploads['orig_name'];
                    
            $this->load->library('image_lib', $config);
            
            $this->image_lib->resize();
            
        }


And the view file!

Code:
<table width="900" border="0" cellspacing="1" cellpadding="1">
        <tr>
          <td valign="top"><div align="center">
            <p class="contentheading">Picture/Image Upload</p>
            <table width="550" border="0" cellspacing="1" cellpadding="3">
              <tr>
                <td><div align="center">&lt;?php echo form_open_multipart('upload/picupload'); ?&gt;
                  <p>1.
                    &lt;input type="file" name="imagefile1" id="imagefile1" /&gt;
                  </p>
                  <p>2.
                    &lt;input type="file" name="imagefile2" id="imagefile2" /&gt;
</p>
                  <p>3.
                    &lt;input type="file" name="imagefile3" id="imagefile3" /&gt;
</p>
                  <p>4.
                    &lt;input type="file" name="imagefile4" id="imagefile4" /&gt;
</p>
                  <p>5.
                    &lt;input type="file" name="imagefile5" id="imagefile5" /&gt;
</p>
                  <p>6.
                    &lt;input type="file" name="imagefile6" id="imagefile6" /&gt;
</p>
                  <p>7.
                    &lt;input type="file" name="imagefile7" id="imagefile7" /&gt;
</p>
                  <p>8.
                    &lt;input type="file" name="imagefile8" id="imagefile8" /&gt;
                    <br />
                    <br />
                    <span class="category">Note: 2MB Per File Size Limit! Any Files Over 2MB Will Not Be Uploaded!</span></p>
                  <p>&lt;?php echo form_submit('mysubmit', 'Upload Pics!'); ?&gt;&lt;?php echo form_close(); ?&gt;</p>
                </div></td>
              </tr>
            </table>
            <p class="stickynote">Image  File Size May NOT Exceed 2 mega bites<br />
            Only JPG, JPEG, GIF, PNG Accpeted</p>
            </div>            <div align="center"></div></td>
          </tr>
      </table>



And right now the model is just a BETA version and I hope to work on it a little more to also create a thumb and move the org file to the users storage folder. But I need to fix this main problem 1st.

Can someone please help me out!! Been working on this for 3 days now and i'm totally stuck. Thanks a million in advance guys!!!

Latavish
#2

[eluser]MCrittenden[/eluser]
Is the process() function ever getting called for the images after the first one? I'm guessing not, but you might stick a simple "echo $uploads['full_path'];" statement or something in it to make sure.
#3

[eluser]charlieD[/eluser]
I'm having the same problem here - I have to make multiple requests in order to get more than one image processed at a time. Is there a queuing system or something like that for the image libraries?
#4

[eluser]phukao[/eluser]
This is the same my problem.
In my opinion, this problem cause from you load library every time you resize.
You can open Image_lib.php in library folder and find initialize() function.
I use this function instead repeat library loading.
It's mean you just change $config['source_image'] to new file you want to resize,
and initialize() before resize again.
#5

[eluser]charlieD[/eluser]
You're right.. In fact, I've come across other annoyances like this when using other libraries. Is this a problem with the way CodeIgniter loads libraries? I've started loading libraries by requiring the file then doing the $img = new ImageEditor() style (which is what I've ended up doing here). Avoids a lot of headaches sometimes...

What's the advantage of using $this->load->library()?
#6

[eluser]phukao[/eluser]
Umm...

I don't think this problem come from CodeIgniter load library, I love it,
but the way we do may not good.
Everything we do is the normal feature, multiple upload, multiple resize,
and I'm sure that a lot of CI programmer passed this point, but how?

The main question is how to initial once, and run many time (with some configuration changing).

Your solution is using new to create new instance with new name for every object.
But in CI, the way to create new instance is using $this->load->library(), which I don't know how to change the object name, so I do initialize() instead.

If you know the general solution, don't forget me, please....
#7

[eluser]ahmad furqon[/eluser]
thanks @phukao

your solution to re-initialize the parameters save my time.
and i dont think this way ruin the ethics of the way codeigniter load the library Smile
#8

[eluser]Aljebrini[/eluser]
i tried to upload two file in my application one ( image ) the other is attached file ( whatever file type doesn't matter )

i tried to initialize the upload library twice before each upload function, but it seems the first file uploaded but the second not !

have look on this :


Code:
$config['encrypt_name'] = true ;
            $config['remove_spaces'] = true ;
            $config['upload_path'] = './uploads/images/';
            $config['allowed_types'] = 'gif|jpg|png|jpeg|bmp';
            $this->load->library('upload');
            $this->upload->initialize($config);
            
            $img = $this->upload->do_upload('img');
            
            
            
            
            unset($config);
            $config['encrypt_name'] = true ;
            $config['remove_spaces'] = true ;
            $config['upload_path'] = './uploads/attachments/';
            $this->upload->initialize($config);
            
            $attachment = $this->upload->do_upload('attachment');



notice that i have to file fields in my views have the names, img and attachment !
#9

[eluser]Aljebrini[/eluser]
[quote author="eng-jebrini" date="1268287827"]i tried to upload two file in my application one ( image ) the other is attached file ( whatever file type doesn't matter )

i tried to initialize the upload library twice before each upload function, but it seems the first file uploaded but the second not !

have look on this :


Code:
$config['encrypt_name'] = true ;
            $config['remove_spaces'] = true ;
            $config['upload_path'] = './uploads/images/';
            $config['allowed_types'] = 'gif|jpg|png|jpeg|bmp';
            $this->load->library('upload');
            $this->upload->initialize($config);
            
            $img = $this->upload->do_upload('img');
            
            
            
            
            unset($config);
            $config['encrypt_name'] = true ;
            $config['remove_spaces'] = true ;
            $config['upload_path'] = './uploads/attachments/';
            $this->upload->initialize($config);
            
            $attachment = $this->upload->do_upload('attachment');



notice that i have to file fields in my views have the names, img and attachment ![/quote]

Code:
solution :

$config['encrypt_name'] = true ;
            $config['remove_spaces'] = true ;
            $config['upload_path'] = './uploads/images/';
            $config['allowed_types'] = 'gif|jpg|png|jpeg|bmp';
            $this->load->library('upload');
            $this->upload->initialize($config);
            
            $img = $this->upload->do_upload('img');
            
            
            
            
            unset($config);
            $config2['encrypt_name'] = true ;
            $config2['remove_spaces'] = true ;
            $config2['upload_path'] = './uploads/attachments/';
            $config2['allowed_types'] = 'gif|jpg|png|jpeg|bmp';
            $this->upload->initialize($config2);
            
            $attachment = $this->upload->do_upload('attachment');




Theme © iAndrew 2016 - Forum software by © MyBB