Tuesday, 15 May 2012

javascript - Success Message after uploading using Dropzone in Laravel -



javascript - Success Message after uploading using Dropzone in Laravel -

am using dropzone upload files in laravel 4.2, below function process files after uploading.

public function postdropfiles() { $file = input::file('file'); $destinationpath = 'uploads/'.auth::user()->username.'/files/'.date('y-m-d'); $extension = file::extension($file->getclientoriginalname()); $filename = time().str_random(12).'.'.$extension; $upload_success = input::file('file')->move($destinationpath, $filename); if( $upload_success ) { homecoming response::json('success', 200);//->with('uploaded','succesiful uploaded'); } else { homecoming response::json('error', 400); } }

the codes works fine , can see when response 200 (success) trying pass variable name called "uploaded" (commented) can display message user files successifully uploaded.

in view have this:

@if(session::has('uploaded')) <div class="notice-box"><strong>{{session::get('uploaded')}}</strong></div> @endif

my aim create session variable after uploading , utilize display message in view. appreciate help. way new laravel.

if using non ajax request

add using session facade;

session::flash('uploaded', 'successfully uploaded.');

this set in session next request , deleted.

if ajax request

pass message value through json info passing ajax request, such as;

response::json(array('success' => true, 'message' => 'successfully uploaded file.'), 200);

edit: on error recommended itachi, error method in ajax called.

response::make(array('success' => false, 'message' => 'error while uploading file.'), 400);

then can check success flag, , display subsequent message wherever want display via jquery.

javascript php laravel laravel-4 dropzone.js

No comments:

Post a Comment