Multiple file upload and progress bar using Ajax

120 views
Skip to first unread message

DEXTER

unread,
Feb 6, 2012, 9:16:07 PM2/6/12
to Centurion project
Hi,
How can I perform multiple file upload with progress bar using Ajax
Is it possible to get individual filenames so that I can move it to
respective folders

Thanks
Dexter

Florent JABY

unread,
Feb 15, 2012, 9:06:13 AM2/15/12
to centurio...@googlegroups.com
Hi,

Centurion can perform multiupload out of the box using some flash+javascript trickery. There has been some work[1] on an HTML5 multiuploader but this is not reasonably usable for websites targetting all browsers.
Anyway, in my project, this is how it's done:

* First of all I specify a manyDependentTable relation in my Table Model class

class Mymodule_Model_DbTable_Post extends Centurion_Db_Table_Abstract
{
    // [....]

    protected $_manyDependentTables = array(
        'gallery' => array(
            'refTableClass'         => 'Media_Model_DbTable_File',
            'intersectionTable'     => 'Mymodule_Model_DbTable_PostGallery',
            'reflocal'     => 'post',
            'refforeign'   => 'media'
        ));
    // [...]
}

as you can see I also have a Momodule_Model_DbTable_PostGallery class which basically is a table listing {post_id, media_id} tuples.

* in my form class, i can add some options about the uploadable content


class Mymodule_Form_Model_Post extends Centurion_Form_Model_Abstract
{
    // [...]
    public function __construct($options = array())
    {
        // Default block
        $this->_elementLabels = array(
            // [...]
            'gallery'           =>  $this->_translate('Gallery')
        );

        parent::__construct($options);
    }
    
    public function init()
    {
        parent::init();

        // Gallery
        $gallery = $this->getElement('gallery');
        $gallery->getFile()->addExtension('jpg,jpeg,png,gif'); // setting allowed extensions
        $gallery->setLabel('Gallery'); // setting label
        $gallery->getFile()->getFilename()->getValidator('Size')->setMax(70*1024*1024); // setting max file size

    }
}

that, is all!

let me know how it works out


DEXTER MCCONNELL

unread,
Feb 16, 2012, 2:44:57 AM2/16/12
to centurio...@googlegroups.com
Thanks
The file upload worked with the sample code supplied by you. The file got uploaded & database also got updated, when I pressed the submit button of my form.

But I could not get the ajax and progress bar to work

What changes should I make in .phtml file ?

Thanks
Dexter
--
...at the entrance gate of Heaven!

Hery RABOTOVAO

unread,
May 14, 2014, 3:35:55 PM5/14/14
to centurio...@googlegroups.com
Hi All.

I can't get multiple upload works correctly. Sometimes it uploads correctly and sometimes it's not.
After uploading a file is done, i must wait about some 10 sec before submit the form to make this features work correctly.
In the other case centurion is writing a bad file id to the database, i don't know why and for finish when centurion doesn't find the good media through the database, all of my uploaded files in the database is showing up on the form.
Reply all
Reply to author
Forward
0 new messages