• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Multiple upload function

#11
[eluser]Référencement Google[/eluser]
As the method returns the $files array it is easy to get back the file name from it (just print_r the returned value to see what exactly).

#12
[eluser]artlover[/eluser]
aha!

$files[0]["file_name"]
$files[1]["file_name"]

are giving the renamed file names!! thanks for clue @Too Pixel Smile

#13
[eluser]Référencement Google[/eluser]
You welcome.

#14
[eluser]luffy[/eluser]
Is it better if I put the function in the model?

#15
[eluser]Zack Kitzmiller[/eluser]
[quote author="luffy" date="1257879826"]Is it better if I put the function in the model?[/quote]

I would. I always keep file uploads in a file model.

#16
[eluser]Référencement Google[/eluser]
I personaly extends the CI_Upload lib in a MY_Upload lib which I think is the most appropriate place to put upload code.

More generally I tend to extend CI first before thinking of putting my code in a model or a helper, eg. if I have to do something about images, I will extend the Image lib.

#17
[eluser]luffy[/eluser]
Most of the time, I use single upload.

I will use multiple upload in a few times.

So I put the function in the model.

#18
[eluser]alrightythen[/eluser]
is this code still correct? because I keep getting the 'The upload path does not appear to be valid' error

#19
[eluser]Référencement Google[/eluser]
The code should still be correct. It is more likely that you must check your upload path, maybe not using the realpath as I did.

#20
[eluser]alrightythen[/eluser]
[quote author="Too Pixel" date="1265158329"]The code should still be correct. It is more likely that you must check your upload path, maybe not using the realpath as I did.[/quote]

Oh hi, a reply from the master himself.
Yes I've tried realpath($upload_dir) and base_url().$upload_dir but neither one of them work

With this code..
Code:
foreach($_FILES as $key => $value)
            {    
                if( ! empty($value['name']))
                {
                    if( ! $CI->upload->do_upload($key))
                    {                                      

                /*    there's something wrong going on here!     */
    
                        $data['upload_message'] = $CI->upload->display_errors();
                        
                        echo 'echo upload_message';
                        echo $data['upload_message'];
                        echo '<br/><br/>';
                        
                        echo 'echo upload_path<br/>';
                        echo $config['upload_path'];
                        echo '<br/><br/>';
                        
                        $errors = TRUE;
                    }
                    else
                    {
                        // Build a file array from all uploaded files
                        $files[] = $CI->upload->data();
                    }
                }
            }

I get..
echo upload_message
The upload path does not appear to be valid.

echo upload_path
/Applications/MAMP/htdocs/costa/uploads

while the $upload_dir = 'uploads'


I'm calling the function like this..
Code:
$this->load->library('upload');
        if(!$files = $this->upload->multiple_upload())
        {
            echo 'Something went wrong during upload';
        }
        else
        {
            echo 'Upload success !<br />';
            echo '<pre>';
            print_r($files);
            echo '</pre>';
        }


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.