Simple PHP code to upload a file (pdf , doc,docx)

Here is the simple php code to upload a pdf file

/* file upload */

 $allowedExts = array("pdf", "doc", "docx"); 
 $targetfolder = $resume_upload_path; // UPLOAD path e.g '/home/public_html/upload'
 $random_num=rand(1000,9999);
$targetfolder = $targetfolder . $random_num.str_replace(' ', '_', basename($_FILES['resume_pdf']['name'])) ;
$targetpath = $root_upload_path . $random_num.str_replace(' ', '_', basename($_FILES['resume_pdf']['name'])) ;

$file_type=$_FILES['resume_pdf']['type'];
$extension = end(explode(".", $_FILES["resume_pdf"]["name"]));


 if ( 12000 < $_FILES["resume_pdf"]["size"]  ) {
 echo "error";  
 exit;
 }

 if ( ! ( in_array($extension, $allowedExts ) ) ) {

  echo "error";  
    exit;
  
 }
 $file_path="";
 if(move_uploaded_file($_FILES['resume_pdf']['tmp_name'], $targetfolder))

 {

 $file_path=$targetpath ;

  }

 else {


  echo "error";  
    exit;
 

 }
 
/* file upload end*/

where $file_path is the path of uploaded file

what is the usage of python lambda functions

Lambda is a keyword used to create an functions without a name or in simple lambda is used to create an anonymous functions,lambda function has n number of argument with a single expression which is processed and returned the result.we know normally a function is defined in python using def statement followed by function name and argument after evaluating it should return the result to get the result value when function is called but lambda has no name and return statement

Syntax Lambda functon

lambda arguments : expression

Example

Tenpercentage= lambda x :x * 10/100  

#"x" is an argument and "x * 10/100" is an expression which got evaluated and returned.   

print(Tenpercentage(200))

print(Tenpercentage(450))

Output

python lambda functions

See above code in Normal functions syntax

def Tenpercentage(n):
  return n * 10/100

print(Tenpercentage(450))

common usage of python lambda functions

Lambda function perform well if we use lambda functions inside another function see example

See example


def currency_convert(currencyvalue):  
    return lambda x:x*currencyvalue;

Israelicurrency=currency_convert(3.48);  #find dollar to Israeli New Shekel

print(Israelicurrency(100));

print(Israelicurrency(900));


indiancurrency=currency_convert(71.57);  #Find dollar to INR

print(indiancurrency(100));

print(indiancurrency(900));

python lambda functions inside anothor function

How to change MySQL root password without knowing the old password ?

Sometime we don’t have any idea about the old MySQL root password,but we have to use root password to manage our application so automatically you are going to behind the topic how to change MySQL root password without knowing the old password,here am using Linux os and we have Linux root ssh login details.So lets find out the steps to change root password

1) Stop the server

 #service httpd stop

2) open MySQL section

 #mysql
  How to change MySQL root password without knowing the old password step 1

3) Select Mysql Database

  > use mysql

4) Update root Password Section

>update user SET password=password(“hello@123”) where user=’root’;

if you are getting error for changing MySQL root password follow steps 5

5) show tables

   > show tables



How to change MySQL root password without knowing the old password step 2

 user table exits

6) Find user table fields

   > describe user
  How to change MySQL root password without knowing the old password step 3
 No password field instead of password we have authentication_string fields

7) Finally update new password

update user SET authentication_string=password("hello@123") where user='root' 

How to install Laravel

Laravel is the one of the most famous PHP web framework, Laravel is a free open-source php framework. Laravel framework is following model–view–controller architectural pattern and based on Symfony, lots of web application using Laravel.It is more secure and fast compared other PHP framework.Lets see how to install Laravel in cPanel

1) Connect to ssh

See How to connect to ssh command prompt using cPanel info

2) Create project directory and download Laravel files to that folder

How to install Laravel in cPanel step 2

3) Move to Laravell folder

 $ cd laravel
 

4) Install Composer

 
 $ composer install
 

How to install Laravel in cPanel step 3

if any version error follow below link

Issue with installing Composer

5) Change you 127.0.0.1 to server ip address

 $ vi vendor/laravel/framework/src/Illuminate/Foundation/Console/ServeCommand.php

 At the end of it you will find were they are configured:
     protected function getOptions()
    {
        return [
            ['host', null, InputOption::VALUE_OPTIONAL, 'The host address to serve the application on', '127.0.0.1'],
            ['port', null, InputOption::VALUE_OPTIONAL, 'The port to serve the application on', '8000'],
        ];
    }

 change 127.0.0.1 to YOUR_IP_ADDRESS and save the files
 


6) Open php artisan serve and generate key

  $ php artisan serve
  $ php artisan key:generate 
  $ php artisan cache:clear

7) open http://YOUR_IP_ADDRESS :8000/myblog/laravel/.env files and change database and server info

How to install Laravel in cPanel step 4

8) Open http://YOUR_IP_ADDRESS:8000/myblog/laravel/public/install to complete your installation

Features of Laravel

1 ) Template Engine : Laravel has a concept of using Blade Templating ,a templating engine to design a unique layout, All Blade templates should use the .blade.php extension.

2) Security : Most of the php framework facing security issues,but Laravel offers very strong security sytem.

3) Artisan : it is the name of the command line interface included with Laravel ,it has alot of usefull command to clear cache, generate key etc
. php artisan key:generate
. php artisan cache:clear
. php artisan config:cache

4) Database Migration System : Migrations are like version control for your database

5) Unit-Testing : Laravel support Unit-Testing