Showing posts with label Slim Framework. Show all posts
Showing posts with label Slim Framework. Show all posts

How to Slim Framework Image Upload

Slim Framework is Micro Framework Similer to core php base. The Slim Framework doesn't have database functionality by default so you can just use core php for that.  And if you do not know how that works Follow Some code.


Image Upload

$app->get("/upload", function () use ($app) {

   $app->view()->setData('username', null);


Image Upload Session Authentication:

$app->post("/upload",function () use ($app){
echo $_FILES['picture']['name'];
echo $_FILES['picture']['size'];
$tmpname = $_FILES['picture']['tmp_name'];
$_SESSION['name'] = "img/".$_FILES['picture']['name'];
move_uploaded_file($tmpname,$_SESSION['name'] );
echo '<img src="'.$_SESSION['name'].'">';

Slim Framework Session Login and sign Up

Slim Framework is Micro Framework Simple code and very powerful web applications and Api.

Micro Framework you can use this middleware to implement HTTP Basic Authentication.By default middleware authenticates array of username and password.  You can also againt database or any other datasource by providing custom authenticator.

Slim Framework Simple Login Authentication Code and Session

require 'class/Slim/Slim.php';
//$app = new SessionCookie();

    $pos = strpos( $_SERVER['PHP_SELF'], '/index.php');
   global $Url;
   $Url = substr( $_SERVER['PHP_SELF'], 0, $pos);
require 'template/View.php';
$View = new View();
$app = new \Slim\Slim([
//'templates.path' => 'assets',
'templates.path' =>  'template','debug'=>true,
'view' => $View
$app->add(new \Slim\Middleware\SessionCookie(array('secret' => 'myappsecret')));

$app->get('/',function()use ($app){
$login = strpos( $_SERVER['PHP_SELF'], '/index.php');
    $baseUrl = substr( $_SERVER['PHP_SELF'], 0, $login);
$app->render('Login.php',array('baseUrl' => $baseUrl ));
$app1 =(Apps::find_by_client_secret($_SESSION['secret']));
$token = Authtoken::find_by_user_id_and_app_id($_SESSION['id'],$app1->app_id);



$routeHelper = function (\Slim\Route $route) {
    echo "Current route is " . $route->getName();if (!isset($_SESSION['username'])) {
            $_SESSION['urlRedirect'] = $app->request()->getPathInfo();
            $app->flash('error', 'Login required');
             // $app->redirect($Url);
$user = function ($app) {
    return function () use ($app) {
global $Url;
  // echo "Current route is " . $route->getCurrentRoute();
        if (!isset($_SESSION['username'])) {
            $_SESSION['urlRedirect'] = $app->request()->getPathInfo();
            $app->flash('error', 'Login required');

Slim Framework View Specify Template or Layout


Slim Framework Simple Registration Model code:

$app->post('/signup',function()use ($app){
//echo 'Hai Im Work Us Slim Framework';
global $Url;

$reg =  new Client();
$username = $app->request()->post('username');
$reg->firstname =  $app->request()->post('firstname');
$reg->lastname =  $app->request()->post('lastname');
$reg->email =  $app->request()->post('email');
$reg->username =  $app->request()->post('username');
$reg->password =  $app->request()->post('password');
//$reg->confirmpassword =  $app->request()->post('confirmpassword');
$reg->dob =  $app->request()->post('dob');
$reg->gender =  $app->request()->post('gender');
$reg->mobilenumber =  $app->request()->post('mobilenumber');
$reg->country =  $app->request()->post('country');
$app->flash('error', 'dob '.$reg->errors->on('dob'));
//$app->flash('error', 'email '.$reg->errors->on('email'));
//$app->flash('error', 'mobilenumber '.$reg->errors->on('mobilenumber'));


Books Will Give More Knowledge - Purchase Books