Welcome Guest, Not a member yet? Register   Sign In
Uploading multiple images and renaming them problem
#1

[eluser]0v3rth3d4wn[/eluser]
Hi! I'm uploading four images, and for each one of them I want to set a new name. I'm using a loop index and php time() function to accomplish this(I use time() because I want unique file_names every time the form is submitted). The problem is my index doesn't concatenate as it should and stays the same on every iteration. I mean the files are uploaded but they all have the same concatenated index in the filename. Here's the code:
Code:
for($i = 1; $i < 5; $i++)
{
    $filename = $i . time();
    $config = array(
         'file_name' => $filename,
         'allowed_types' => 'jpg|jpeg|gif|png',
         'upload_path' => $path,
         'max_size' => '2048'
    );                  
    $this->load->library('upload', $config); //load the upload library                    
    $this->upload->do_upload('image_'.$i);
}
And after the upload the files in my upload folder are: 11326113826.png, 113261138261.png, 113261138262.png, 113261138263.png. As you can see the first digit of the file name should be my index, but is always "1". I'm not overwriting so CI adds another digit at the end because of same file names, but that's not the point, I want to use my index for customizing my file names. I've done this before, without CI, but this project I'm building is with CI, so any ideas? I'm stuck for an hour on this. The idea is each time to use different $config array, with the new $filename value, but somehow the value stays the same. Also when I print the $i index everything is OK it says:"1,2,3,4", and the files are successfully uploaded. I'm also doing validation but assume that all the images are valid.
Sorry for the long post!

Thanks in advance!




Theme © iAndrew 2016 - Forum software by © MyBB