Bribin's avatar

Dropzone js + File Upload File Order

Hi, Im developing a project with Dropzone file upload, i want to pass the order of dropone file into data base , how i can save the order/position of the file in database

    $file = Input::file('file');
        $campaign =  Campaign::getCampaign($id);
           
        $uploadPath = 'uploads/stores/'.$campaign->store->id.'/'.$id.'/';
        $destinationPath = '/uploads/stores/'.$campaign->store->id.'/'.$id.'/';
        $filename = $id .'-'.$campaign->store->id.$file->getClientOriginalName();
        $upload_success = Input::file('file')->move($uploadPath, $filename);

            if ($upload_success) {
                    // resizing an uploaded file
                $thumb = Image::make($uploadPath.$filename)->resize(184, NULL,  function ($c) {
                    $c->aspectRatio();
                    $c->upsize();
                });
                $thumb->save($uploadPath.'thumb_'.$filename);
            }

        $campaign->flyers()->create(
                 ['path' => $destinationPath.$filename, 'order'=> $i ,'thumbnail'=>    $destinationPath.'thumb_'.$filename]
        );
    return  'success';

dropzone .js config

     Dropzone.options.addflyer = { 
         uploadMultiple: false,
            parallelUploads: 1,
         maxFilesize: 8,
         autoProcessQueue: false,
            addRemoveLinks: true,
            dictRemoveFile: 'Remove',
            dictFileTooBig: 'Image is bigger than 8MB',
              
             };
0 likes
2 replies
unitedworx's avatar

What I do is have a sort field in my images table which gets increments every time I save an image in my database

Then using drag and drop I can order my images, which is another subject on its own.

I actually created a service provider which makes sure to increment the sort field each time a new model is saved if I specified if it has an attribute autoIncrementSort set to true! Which makes this work across all my models I want to be able to sort!

<?php namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use \Event;
use \DB;
class SortIncrementServiceProvider extends ServiceProvider {

    public function register()
    {
        $this->registerEvents();

    }


    public function registerEvents()
    {
        Event::listen('eloquent.creating*', function ($model) {
            if ($model->autoIncrementSort) {
                $model->sort = DB::table($model->getTable())->max('sort') + 1 ;
            }
        });
    }

}


jekinney's avatar

From my experience for each photo dropped whether one or many at the same time it sends separate requests for each. You could increment on your own by counting how many are in the database reference if your saving information to a database and add 1 to the count.

Please or to participate in this conversation.