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> </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)]); } } }
Harsh
source share