Blueimp / jQuery-File-Upload with Laravel How to integrate?

Trying to create my uploadable images on my site and wanted to use blueimp / jQuery-File-Upload instead of hardcoding from scratch. However, I am also too new, could you tell me HOW to integrate this plugin with your Laravel framework ?

Where can I put all the files? In the suppliers folder? Or should I split all the folders and put their js folder in mine, etc ???

If you know the tutorial, it's even better ... Could not find anything good with Google.

thanks

+7
jquery php laravel image-uploading
source share
1 answer

You can try this code that I am posting to help others.

The first step is to define the Route s download and download page, for example:

 Route::get('image_', function() { return View::make('image.upload-form'); }); Route::post('image_updade', ' ImageController@postUpload '); 

Make your image.upload-form look something like this (I use plain HTML, not the Blade template):

 <?php echo Form::open(array('url' => 'image_updade', 'files' => true, 'id' => 'myForm')) ?> Name: <input type='file' name='image' id='myFile'/> <br/> Comment: <textarea name='comment'></textarea> <br/> <input type='submit' value='Submit Comment' /> <?php echo Form::close() ?> 

Now you need to add the JavaScript files to this page with the <HEAD> tags:

 <script src='http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js'></script> <script src='http://malsup.github.com/jquery.form.js'></script> <script> // Wait for the DOM to be loaded $(document).ready(function() { // Bind 'myForm' and provide a simple callback function $('#myForm').ajaxForm(function() { alert('Thank you for your comment!'); }); $('#myFile').change(function() { $('#myForm').submit(); }); }); </script> 

Finally, here is a simple example code for the ImageController@postUpload controller to download the downloaded file and move it to the destination folder:

 <?php class ImageController extends BaseController { public function getUploadForm() { return View::make('image/upload-form'); } public function postUpload() { $file = Input::file('image'); $input = array('image' => $file); $rules = array( 'image' => 'image'); $validator = Validator::make($input, $rules); if ( $validator->fails() ){ return Response::json(['success' => false, 'errors' => $validator->getMessageBag()->toArray()]); } else { $destinationPath = 'files/'; $filename = $file->getClientOriginalName(); Input::file('image')->move($destinationPath, $filename); return Response::json(['success' => true, 'file' => asset($destinationPath.$filename)]); } } } 
+7
source share

All Articles