1

I have integrated Jquery file uploader plugin via https://blueimp.github.io/jQuery-File-Upload/. Its working perfectly. I have placed the server folder of the plugin in /public of laravel. Now i have to use the session variable to check the maximum file size available for particular user, authenticating user etc. There are two files in server/php if you can see. I am trying to use like this, which is not affecting anything. if (session_id() == '') { @session_start(); /* or Session:start(); */ } $uid=$_SESSION['id']; print $uid;

I also tried the same thing in the userController.php's constructor using $this->uid=$_SESSION['id']; Nothing seems working . I am not understanding how to access sessions in this. Or any other way via which i can try? Thank You!

1
  • Are you routes under web middleware? You need to post your code at least routes.php and your controller as well that handle the ajax or upload request. Commented May 11, 2016 at 17:17

1 Answer 1

1

12-05-16-vh Implimenting Jquery file uploader to laravel

https://blueimp.github.io/jQuery-File-Upload/

Download the zipfile from above link put them in public folder(I have placed in public/asset/vender/) The server/php is the one where the important codes(index.php, uploadhandler.php) where kept. If use that, the sessions cannot be accessed.

Best way is to make customization to the code update main.js in /js folder of the plugin byChanging this line url: 'server/php/' to some controller route eg: url: 'file_uploader' then in the routes.php, give connection to a controller class for file_uploader'

Route::post('file_uploader', 'userController@file_uploader');

Route::get('file_uploader', 'userController@file_uploader'); Route::DELETE('file_uploader', 'userController@file_uploader');

In the userController, create a function, which can then initate the instance of the uploadHandler class(which we are going to place in seperate controller) add this in beginnig of userController use App\Http\Controllers\UploadHandler;

and then have this method which creates instance of UploadHandler

public function file_uploader(Request $request)
{
     $upload_handler = new UploadHandler();
}

create a controller named UploadHandler, add all the namespaces and other stuffs, copy the class UploadHandler which is there in UploadHandler.php of the plugin. Now in this UploadHandler class contrsuctor you can call Your sessions(make sure to write use Session; in beginning of controller.

For deleting file, update $file->deleteUrl object public function set_additional_file_properties($file) and it should look like below now

$file->deleteUrl= 'file_uploader?'
        .$this->get_singular_param_name()
        .'='.rawurlencode($file->name);

I am posting a gross answer above, You can do some workaround to make it accessible.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.