Session not working in Jquery file upload plugin integration, laravel 5 - php

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!

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.

Related

need to execute a function at after login screen

I need to display a custom alert at the home page only once, so I used authenticated function in AuthenticatesUsers.php file. It's working perfectly, but the problem is vendor folder doesn't push to git:/?
Any solution to this problem?
You can't really change vendor files as they are meant to be installed whenever you clone repo. However, you can override authenticated method in your LoginController inside
Controllers/Auth/LoginController.php
protected function authenticated()
{
}

Can't find the true url in a php project using Yii2

I'm new in php coding and I'm using Yii2 framework
I'm trying to make a simple project as follow:
I added a .php file named "PostController.php" in the backend/controllers and I wrote this codes in this file:
<?php
namespace backend\controllers;
use yii\web\Controller;
class PostController extends Controller
{
public function actionIndex()
{
return $this->render('index');
}
}
?>
and I created a file in beckend/views named "post" and in this folder I created a.php file named index.php
then I just wrote one line in index.php for test as bellow:
<h1>Hello World</h1>
Now I want to see this index file (Hello World) in my browser. Which url I should enter in my browser to see that? I tried the bellow url and it didn't worked!:
projectname.loc/index.php?r=post/index
if pretty url is true then you have to access the controller like
localhost/projectname/backend/web/index.php/controller/action
if pretty url is false then you have to access the controller like
localhost/projectname/backend/web/index.php?r=controller/action
if you project is in your local machine, if its on your server then you have to write server name instead of localhost
You should go to projectname.loc/post (or projectname.loc/post/index), to be in this action. before that you have to turn on the "prettyUrl" in your urlManager
If you use basic tamplate from yii2 your namespace must be app/backend/controllers and you should go to projectname.loc/index.php?r=backend/post/index
"backend" it will be a path to your controller, not a module

How to connect codeigniter controller method from Jquery code in a view file (placed in folder)

I am using the autocomplete plugin in Jquery as follows:
$(function(){
$("#username").autocomplete({
source: "http://localhost/websitename/index.php/admin/suggest_names" // path to the method in controller
});
});
The code for the text box is
<input type="text" name="username" id="username">
The suggest_names method in controller in turn calls a method in the model
I have tried providing the path to the method in controller by using
source: "admin/suggest_names"
in the above code.
However this is not working when the file is placed in a sub folder within the views folder application/views/admin. This works when the file is placed directly within the views folder.
I have tried using site_url but this does not work as well. (the form helper function is loaded in the administrator)
Can you suggest where I am making a mistake and suggest the syntax for the code to be used.
Stick to the following structure:
VIEW:
Your jquery function must be in a view file (it can be in the
Application/Views
directory or in a subdirectory of view). A view file is displayed in the browser and so the jquery code can run on client side. The controller is called from here. Your first code block example seems to be correct. You can also use: source: "/index.php/admin/suggest_names".
CONTROLLER:
A Controller (in your case called admin) is simply a class file that is named in a way that can be associated with a URI. They are placed in the
Application/Controllers
directory or a subdirectory of it. In your case you are calling the function suggest_names(), where you prepare the $data you want to output in the view file and call the database functions from a model (that last one is optional, you could treat the database functions from the controller as well).
MODELS:
Models are PHP classes that are designed to work with information in your database. They are placed in the
Application/Models
directory or subdirectory of it.

How to start a new website project in codeigniter?

I'm really beginner to codeigniter I'm working on CI since last 2 weeks. During this period I have created many views.php files, some controllers.php files and some models.php files
Now I want start a new website project.
What should I do. Should I delete all files of my controllers, views and models, etc., and download another codeigniter and start from the beginning?
You should check the documentation of codeigniter for help but just to give you a quick start ill explain how to create your first codeigniter project.
Installation
1 Download the codeigniter framework from http://ellislab.com/codeigniter
2 upload it in root directory of your website or local apache server directory.
Creating your codeigniter project.
In codeigniter your controller will handle the url requests and load appropriate model and views. So the first step is to create your controller.
1 Creating your controller: go to Applications->controllers and there you will find a built in controller called welcome.php.
This controller loads a view welcome_message.php which is inside Application->views.
You can use this controller or create your own.
To create your own controller create a new php file myfirstcontroller.php and extend a class with same name from CI_Controller.
Note that the name of the file and your class name should be the same. the index function is the default function that will be called when you make a request to the controller
class myfirstcontroller extends CI_Controller {
public function index(){
$this->load->view("myfirstview");
}
}
so when you request this controller through yoursite/index.php/myfirstcontroller
it will load a view called myfirstview.php which will reside inside applications->views.
Go ahead and create this file in applications ->views.
2 To pass data from controller to view you will send an array to the view
class myfirstcontroller extends CI_Controller {
public function index(){
$data['name']="My first application.";
$this->load->view("myfirstview",$data);
}
}
3 You can access this variable in view
echo $name
and it will output your variable
3 you use models you have to create a file inside applications->models and call it from controller and it will return the result in the form of array.
You can look at the documentation for further help.
Hope this helped you to get started with codeigniter.
The user guide is inside your download library.
You can also view it in http://ellislab.com/codeigniter/user-guide/
Good luck!!!
Here is Phil Sturgeon's article on how to do multiple site on one CI instance, in here he explains 2 ways of doing it and describes pros and cons.
http://philsturgeon.co.uk/blog/2009/07/Create-an-Admin-panel-with-CodeIgniter
But in his latest articles he has told what happened to modular separation.
http://philsturgeon.co.uk/blog/2010/03/modular-separation-codeigniter-2

REST Service not working-Code Igniter

I want to implement a Phill Sturgeon CodeIgniter RESTServer library in my project. I copied the files rest.php, Format.php, REST_Controler.php in folders config,library,library respectively.
I created my controller called services with following code:
<?php
require(APPPATH.'/libraries/REST_Controller.php');
class services extends REST_Controller {
function Teams_get(){
$teamNames=$this->team_model->getTeamNames();
$this->response($teamNames);
}
TeamModel is autoloaded in my autoload.php. When I want to run Teams_get method in my browser result is:
{"status":false,"error":"Unknown method."}
I read here that I should change REST_Controler.php configuration file, but this change should only be done if POST methods are not working.
My services should be public, so I don't need authentication methods.
What's wrong here?
When calling your API, the URL should just be the name of the method, without the _get (or _post). That is added by the REST server depending on how the URL is called (GET vs POST).
So, to call your Teams_get method, you want to send a GET request to the URL /services/Teams (not /services/Teams_get).
Docs: https://github.com/philsturgeon/codeigniter-restserver#handling-requests

Categories