theUnforgiven's avatar

Multiple image upload [suggestions]

Hi all,

Having tried Dropzone its a little but overwhelming and too much for what I need, basically, Ive built a little site for my band and I want to be able to upload multiple images, with thumbnails and store them in a "uploads" folder within the public dir.

So, I'm looking for suggestions on what to use or how to build something simple.

0 likes
14 replies
jlrdw's avatar

Not laravel but similar, it is easy

 public function add() {
        if (isset($_POST['submit'])) {
            $lid = DB::table('recents')->count();
            $k = -1;
            if (empty($lid) || strlen($lid) == 0 || is_null($lid)) {
                $lid = 1;
            }
            $newname = '';
            $destinationPath = ROOTDIR . 'upload/imgrecent/';
            $files = Input::file('ufile');
            //$names = [];
            $arrname = [];
            foreach ($files as $file) {
                $k = $k + 1;
                if (empty($file)) {
                    $arrname[$k] = "";
                } else {
                    $file_name = $file->getClientOriginalName();
                    $file_ext = $file->getClientOriginalExtension();
                    $lid = $lid + $k + 1;
                    $fileInfo = pathinfo($file_name);
                    $filename = $fileInfo['filename'];
                    print_r($filename);
                    $arrname[$k] = $filename . $lid . "." . $file_ext;
                    $file->move($destinationPath, (string) $arrname[$k]);
                }
            }
            $pic1 = Cln::fixValue((string) $arrname[0]);
            $pic2 = Cln::fixValue((string) $arrname[1]);
            $pic3 = Cln::fixValue((string) $arrname[2]);
            $pic4 = Cln::fixValue((string) $arrname[3]);
            $comments = Cln::fixValue($_POST['comments']);
            if (!isset($error)) {
                $postdata = array(
                    'pic1' => $pic1,
                    'pic2' => $pic2,
                    'pic3' => $pic3,
                    'pic4' => $pic4,
                    'comments' => $comments
                );
                DB::table('recents')->insert($postdata);
            }
        }//end add        

        $this->layout = 'addtpl';
        return View::make('Recents/Add')->shares('title', 'Recent Add');
    }

Also file uploading is delt with in the docs.

theUnforgiven's avatar

Looking for more the javascript/ajax side than the laravel side of things

jekinney's avatar

Drop zone is great but overwhelming to customize quickly if you haven't used it. Almost like a mini framework. But lacks meaningful tutorials.

1 like
theUnforgiven's avatar

Thanks guys, I since remember Jeff doing the "Project Flyer" series, which now I have dropzone working, (smacks head in disgust)

theUnforgiven's avatar

So with that in mind.... (see image)

I have two form fields I need passing to the same "upload" method which is year and location so I can use that to store the images in the correct locations.

Or would this just be within the request object? Or do I need to pass something specially to the dropzone object?

theUnforgiven's avatar

I'm getting array('request' => object(Request), 'files' => null, 'names' => array())) no files when using the dropzone lib, any ideas on why this would be?

kenny11's avatar

Do you mean there is no file in request?

Can you not do request()->file('file');?

theUnforgiven's avatar

@kenny11 I have

$files = $request->file('file');
        $names = [];
        foreach($files as $file) {
            $names[] = $file->getClientOriginalName();
            print_r($names);

        }

Which results in

kenny11's avatar

@theUnforgiven

Do you have parallel upload on for your drop zone.js settings??

If not you don't need to foreach since a image you upload is on queue.

theUnforgiven's avatar

I have in the JS

url: "/admin/gallery/upload",
               maxFilesize: 2,
               autoDiscover: false,
               autoProcessQueue: false,
               uploadMultiple: true,
               parallelUploads: 25,
theUnforgiven's avatar

anyone have any suggestions on this, really stuck why it's not showing all files.

Please or to participate in this conversation.