Welcome Guest, Not a member yet? Register   Sign In
Insert uploaded filenames into specific SQL columns
#5

[eluser]n0xie[/eluser]
This implies that you upload the images at the same time you are creating the entry. Is this correct?

If so you could do something like that:
Code:
# pseudo code
class Entries extends CI_Controller

    function create()
    {
        // all your form validation crap here
        // if they pass:
        
        $images = $this->_handle_upload();
    
        // do damage control here if something went wrong with the file upload
        if ( ! $images) show_404('something went wrong during upload');
    
        $data = array_merge($data, $images);
        
        $this->entries_model->save($data);
    }
    
    function _handle_upload()
    {
        // put all your upload code here (basically c/p your create() function)
        
        // inside your foreach loop
        
        // instead of inserting we do:
        $fieldname = 'img' . $i;
        $fieldname_small = 'img' . $i . 'sml';
        $image[$fieldname]    =  $imagename;
        $image[$fieldname_small] = str_replace('_tn','_tn2', $imagename);
        
        $i++;
        
        // end foreach loop
        
        return ($error) ? FALSE : $image;
        
    }

Obviously you could move the upload stuff to a different library/module/model instead of doing it in the controller.


Messages In This Thread
Insert uploaded filenames into specific SQL columns - by El Forum - 01-26-2011, 02:44 PM
Insert uploaded filenames into specific SQL columns - by El Forum - 01-27-2011, 09:38 AM
Insert uploaded filenames into specific SQL columns - by El Forum - 01-28-2011, 03:46 AM
Insert uploaded filenames into specific SQL columns - by El Forum - 01-28-2011, 03:52 AM
Insert uploaded filenames into specific SQL columns - by El Forum - 01-28-2011, 04:21 AM
Insert uploaded filenames into specific SQL columns - by El Forum - 01-28-2011, 04:24 AM
Insert uploaded filenames into specific SQL columns - by El Forum - 01-28-2011, 04:49 AM
Insert uploaded filenames into specific SQL columns - by El Forum - 01-28-2011, 05:42 AM
Insert uploaded filenames into specific SQL columns - by El Forum - 01-28-2011, 05:56 AM
Insert uploaded filenames into specific SQL columns - by El Forum - 01-28-2011, 06:07 AM
Insert uploaded filenames into specific SQL columns - by El Forum - 01-28-2011, 07:52 AM
Insert uploaded filenames into specific SQL columns - by El Forum - 01-28-2011, 07:54 AM
Insert uploaded filenames into specific SQL columns - by El Forum - 01-28-2011, 07:58 AM
Insert uploaded filenames into specific SQL columns - by El Forum - 04-18-2011, 11:44 AM
Insert uploaded filenames into specific SQL columns - by El Forum - 04-20-2011, 10:38 AM



Theme © iAndrew 2016 - Forum software by © MyBB