Topic: php

Laravel 6 Delete Directory using File Storage 0

Laravel 6 Delete Directory using File Storage

Today, We want to share with you Laravel 6 Delete Directory using File Storage.In this post we will show you wordpress plugin require another plugin, hear for How to delete files if exists from public folder in Laravel 6 with example we will give you demo and example for implement.In this post, we will learn about How to delete directory in Laravel 6?, with an example.

Laravel 6 Delete Directory using FileStorage

There are the Following The simple About PHP Delete Directory using File Storage Full Information With Example and source code.

As I will cover this Post with live Working example to develop php – Laravel 6 File Storage delete all files in directory,, so the Laravel 6 Delete a Folder with Storage or File Class is used for this example is following below.

how to delete folder in laravel 6

Using File System:

public function deleteUploadedFolder()
{
    $orignal_path = public_path('movies');
    $finalResults = File::deleteDirectory($orignal_path);
    dd($finalResults);
}

how to remove directory in laravel 6

Using Storage System:

public function deleteUploadedFolder()
{
    $finalResults = Storage::deleteDirectory('movies');
    dd($finalResults);
}

laravel 6 delete folder with files

Using Core PHP:

public function deleteUploadedFolder()
{
    $orignal_path = public_path('movies');
    $finalResults = rmdir($orignal_path);
    dd($finalResults);

}

Web Programming Tutorials Example with Demo

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Laravel 6 Delete Directory.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Nested try catch block in PHP – Exception handling 0

Nested try catch block in PHP - Exception handling

Today, We want to share with you Nested try catch block in PHP – Exception handling.In this post we will show you wordpress plugin require another plugin, hear for Multiple catch blocks and nested try blocks we will give you demo and example for implement.In this post, we will learn about Multiple catch blocks with single try block with an example.

Nested try catch block in PHP – Exception handling

There are the Following The simple About Nested try catch block in PHP – Exception handling Full Information With Example and source code.

As I will cover this Post with live Working example to develop php exception handling best practices, so the php try finally without catch is used for this example is following below.

Simple PHP Example for try-catch

You can also extend the exception class as follows:

php_try_catch.php

<?php
try{
 $products = count($_GET);
 if($products!=0) {
  foreach($_GET as $key=>$value) {
   echo $key . " = " . $value . "<br/>";
  }
 } else {
  throw new Exception("PHP REQUEST GET global array is empty");
 }
}
catch(Exception $e) {
 echo $e->getMessage();
}
?>

PHP Try Catch Exception & Error Handling Tutorial

PHP try with Multiple catch

php_multiple_catch.php

<?php
$current_time_stemp1 = array(1,2,3,"four",5,6);
try{
 $my_timestamp1 = get_timestamp($current_time_stemp1);
 print "PHP time stamp - " . $my_timestamp1 . "<br/>";
}
catch(Exception $e) {
 echo $e->getMessage();
}
catch(InvalidArgumentException $e) {
 echo $e->getMessage();
}

function get_timestamp($current_time_stemp) {
 $current_time_stemp_length = count($current_time_stemp);
 if($current_time_stemp_length!=0) {
  for($i=0;$i<$current_time_stemp_length;$i++) {
   if(!is_numeric($current_time_stemp[$i])) {
    throw new InvalidArgumentException("Please parameter $i should be numeric, " . gettype($current_time_stemp[$i]). " is given");
   }
  }
 } else {
  throw new Exception("Sorry, no Any argument is passed for Date timestmap calculating.");
 }
 $timestamp = mktime($current_time_stemp[0], $current_time_stemp[1], $current_time_stemp[2], $current_time_stemp[3], $current_time_stemp[4], $current_time_stemp[5]);
 return $timestamp; 
}
?>

Nested try-catch in PHP

php_try_catch_nesting.php

//Nested try-catch in PHP
try{
do_upload_file("data.json");
}
catch (Exception $e){
	echo $e->getMessage() . "<br/>";
	while($e = $e->getPrevious()) {
		echo 'Previous Error: '.$e->getMessage() . "<br/>";
	}
}
function do_upload_file( $json_file){
	try{
		if(file_exists($json_file)){
			//PHP File Upload
			echo "Sorry, file already exists.";
			// code for file uploading
		} else {
			throw new Exception( 'file not found');  
		}
	}
	catch (Exception $e){
		throw new Exception( 'Sorry!!, unable to upload file',0,$e);
	}
}

PHP Extending the Exception class

Nested try catch Exception Handaling in PHP (exceptional-php-nesting-exceptions-in-php.php)

class MyException extends Exception{}

try {
 try {
   throw new MyException;
 } catch(MyException $e){
   echo "second:";
   throw $e;
 } catch(Exception $e){
   echo "first:";
   throw $e;
 }
}catch(Exception $e){
	echo get_class($e);
}


echo "<hr/>";

Web Programming Tutorials Example with Demo

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Nested try catch block in PHP – Exception handling.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Simple PHP Convert Date Format Examples 0

Simple PHP Convert Date Format Examples

Today, We want to share with you Simple PHP Convert Date Format Examples.In this post we will show you PHP Change Date Format From YYYY-MM-DD to DD-MM-YYYY , hear for convert mysql date to dd mm yyyy format in php we will give you demo and example for implement.In this post, we will learn about PHP program to change date format with an example.

Simple PHP Convert Date Format Examples

There are the Following The simple About Simple PHP Convert Date Format Examples Full Information With Example and source code.

As I will cover this Post with live Working example to develop How to change date format in PHP?, so the some major files and Directory structures for this example is following below.

Convert yyyy-mm-dd to mm/dd/yyyy in PHP

In this PHP example I shall add “2020-04-25” with (YYYY-MM-DD) format and I shall change into MM/DD/YYYY format in php.

$userFormDate = "2020-04-25";
  
$userConvertDt = date("m/d/Y", strtotime($userFormDate));
   
print_r($userConvertDt);

Output:

04/25/2020

Convert yyyy-mm-dd to dd-mm-yyyy in PHP

In this PHP example I shall add “2020-04-25” with (YYYY-MM-DD) format and I shall change into DD-MM-YYYY format in php.

$userFormDate = "2020-04-25";
  
$userConvertDt = date("d-m-Y", strtotime($userFormDate));
   
print_r($userConvertDt);

output

25-04-2020

Convert dd/mm/yyyy to yyyy-mm-dd in PHP

In this PHP example I shall add “25/04/2020” with (DD/MM/YYYY) format as well as I shall change into YYYY-MM-DD format in php.

$userFormDate = "25/04/2020";
   
$userFormDate = str_replace('/', '-', $userFormDate );
$userConvertDt = date("Y-m-d", strtotime($userFormDate));
   
print_r($userConvertDt);

output

2020-04-25

Web Programming Tutorials Example with Demo

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about PHP Convert Date Format.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

PHP Config Class to store configuration data 0

PHP Config Class to store configuration data

Today, We want to share with you PHP Config Class to store configuration data.In this post we will show you wordpress plugin require another plugin, hear for Config Class Object Oriented PHP for Beginners we will give you demo and example for implement.In this post, we will learn about $settings array or Config Class to store project settings with an example.

PHP Config Class to store configuration data

There are the Following The simple About PHP Config Class to store configuration data Full Information With Example and source code.

As I will cover this Post with live Working example to develop php application configuration,, so the PHP Config Class – Setting and Getting Property Values is used for this example is following below.

PHP classes to store configuration data

PHP OOP Configuration class. Used for managing runtime Database connection or more configuration information.It’s Used to store a dynamic variable in Configure.

htdocs/social-api/src/Pakainfo/social/Config

<?php
namespace Pakainfo\social\Config;

class Config
{
    protected static $config = array();

    private $channel_name;
    public function __construct($channel_name)
    {
        $this->channel_name = $channel_name;
    }
    public function get($name, $default = null)
    {
        return isset(self::$config[$this->channel_name][$name]) ? self::$config[$this->channel_name][$name] : $default;
    }
    public static function add($parameters = array())
    {
        self::$config = array_merge(self::$config, $parameters);
    }
}

Config::add(
    [
       /*
        |--------------------------------------------------------------------------
        | mysql Database connection
        |--------------------------------------------------------------------------
        |
        | This file is for setting the credentials for mysql api db_username and db_password.
        |
        */
        'mysql' => [
            'db_username' => 'web_blogs_tamilrokes_new_link',
            'db_password'  => '[email protected]',
            'db_name' => 'tamilrokers';
        ]
    ]
);

/opt/lampp/htdocs/social-api/src/Pakainfo/social/Database

<?php

namespace Pakainfo\social\Database;
use Pakainfo\social\Config\Config;

class Database
{
    public $website_name;
    private $image_dir;
    private $db_password;
    private $db_username;
    private $db_name;
    private $config;

    public function __construct($channel_auth)
    {
        $this->config = new Config("mysql");
        $this->website_name = $channel_auth['website_name'];
        $this->db_password = $this->config->get("db_password");
        $this->db_username = $this->config->get("db_username");
        $this->image_dir = $channel_auth['image_dir'];
        $this->db_name = $this->config->get("db_name");
        
    }
}

Web Programming Tutorials Example with Demo

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about PHP DbConfig Class to store configuration data.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

PHP Try Catch Exception & Error Handling Tutorial 0

PHP Try Catch Exception & Error Handling Tutorial

Today, We want to share with you PHP Try Catch Exception & Error Handling Tutorial.In this post we will show you wordpress plugin require another plugin, hear for Exception Handling & Error Reporting – PHP Tutorial we will give you demo and example for implement.In this post, we will learn about Using PHP try catch throw Techniques to Handle Exceptions with an example.

PHP Try Catch Exception & Error Handling Tutorial

There are the Following The simple About PHP Try Catch Exception & Error Handling Tutorial Full Information With Example and source code.

As I will cover this Post with live Working example to develop Throwing exceptions in a PHP Try Catch block, so the PHP 5 Exception Handling using try, catch and throw is used for this example is following below.

What is an Exception?

PHP – An error is an unexpected computer program result data that cannot be handled by the computer program itself.

PHP Error handling is the one type process of catching all the errors raised by your main computer program and then taking related/appropriate action.

Introduction To PHP Exception Handling,What is an Exception,Try, throw and catch,Custom Exception Class,Multiple,Re-throwing,Set a Top Level Exception Handler.

PHP Error handling

  • Die statements
  • Custom error handlers
  • PHP error reporting

Source of the native class Exception Source Code : PHP Try Catch Exception

<? php
    class Exception 
    {
    	// Message of exception
        protected $ message = 'Unknown exception'; 

        // Exception code defined by the user  
        protected $ code = 0;  

        // Source filename of exception
        protected $ file; 

        // Source line of the exception
        protected $ line; 
        function __construct (string $ message = NULL, int code = 0);

        // Message of exception
        final function getMessage (); 

        // Exception code
        final function getCode (); 

        // Source filename
        final function getFile (); 

        // Line of the source file
        final function getLine(); 

        // An array of backtrace ()
        final function getTrace (); 

        // Formatted string trace
        final function getTraceAsString (); 
        / * * Replaceable /

        // Formatted string for display
        function __toString (); 
    }
?>

PHP try, throw and catch

Error handling examples

creating a function containing a potential exception

<?php
  
  function statusNumber($num_ber) {
    if($num_ber > 1) {
      throw new Exception('The Data value has to be 1 or lower');
    }
    return true;
  }

  try {
    statusNumber(2);
    echo 'The Data value is 1 or lower';
  } catch(Exception $e) {
    echo 'Message: ' .$e->getMessage();
  }
?>

PHP Custom Exception Class

<?php
  class generalException extends Exception {
    public function error_message() {
      $error_msg = 'Error caught on line '.$this->getLine().' in '.$this->getFile()
        .': <b>'.$this->getMessage().'</b> is no valid E-Mail address';
      return $error_msg;
    }
  }

  $email = "[email protected]";

  try {
    if(filter_var($email, FILTER_VALIDATE_EMAIL) === FALSE) {
      throw new generalException($email);
    }
  } catch (generalException $e) {
    echo $e->error_message();
  }
?>

PHP Multiple Exceptions Handling

<?php
  class generalException extends Exception {
    public function error_message() {
      //error message
      $error_msg = 'Error caught on line '.$this->getLine().' in '.$this->getFile()
        .': <b>'.$this->getMessage().'</b> is no valid E-Mail address';
      return $error_msg;
    }
  }

  $email = "[email protected]";

  try {
    if(filter_var($email, FILTER_VALIDATE_EMAIL) === FALSE) {
      throw new generalException($email);
    }
    if(strpos($email, "example") !== FALSE) {
      throw new Exception("$email contains'example'");
    }
  }
  catch (generalException $e) {
    echo $e->error_message();
  }
  catch(Exception $e) {
    echo $e->getMessage();
  }
?>

PHP Re-Throwing Exceptions

In this example learn to :checking for “gmail” in mail address, throwing an exception if email is not valid, re-throwing exception, display custom message in PHP Try Catch Exception.

<?php
  class generalException extends Exception {
    public function error_message() {
      //error message
      $error_msg = $this->getMessage().' is no valid E-Mail/gmail address.';
      return $error_msg;
    }
  }

  $email = "[email protected]";

  try {
    try {
      if(strpos($email, "gmail") !== FALSE) {
        throw new Exception($email);
      }
    } catch(Exception $e) {
      throw new generalException($email);
    }
  } catch (generalException $e) {
    echo $e->error_message();
  }
?>

Top Level Exception Handler in PHP

<?php
  function CustomException($exception) {
    echo "<b>Your Exception is </b> " . $exception->getMessage();
  }

  set_exception_handler('CustomException');

  throw new Exception('Sorry!!, Uncaught Exception has been caught');
?>

Simple PHP Exception Handling

  1. php exception class
  2. php try catch fatal error
  3. php exception types
  4. php catch warning
  5. set_exception_handler
  6. php exception codes

Basic Usage

<?php
function check_num($number) {
  if($number>1) {
    throw new Exception("The value has to be 1 or lower");
  }
  return true;
}

check_num(3);
?>

PHP Try Catch: Basics & Advanced PHP Exception Handling Tutorial

Simple PHP try catch example

try {
    // run your simple PHP code here
}
catch (exception $e) {
    //PHP code to handle the error/exception
}
finally {
    //here optional source code that always runs
}

PHP try catch with multiple exception types

try {
    // run simple your PHP code here
}
catch (Exception $e) {
    echo $e->getMessage();
}
catch (InvalidArgumentException $e) {
    echo $e->getMessage();
}

Global PHP exception handling

function custome_global_exception_handler($exception) {
    echo "Our Exception:" . $exception->getMessage();
}

set_exception_handler(‘custome_global_exception_handler’);

PHP Exception Handling Examples:

Exception handling in PHP:

<?php 

function website($var) { 
	echo " Before try block"; 
	try { 
		echo "\n Inside try block"; 
			
		if($var == 0) 
		{ 
			
			throw new Exception('Number is zero.'); 
			echo "\n After throw (It will never be executed)"; 
		} 
	} 
		
	catch(Exception $e) { 
			echo "\n Exception Caught", $e->getMessage(); 
		} 
		
		echo "\n After catch (will be always executed)"; 
} 

website(5); 
website(0); 
?> 

normal try catch and finally block in PHP

<?php 
function website($var) { 
	
	echo " Before try block"; 
	try { 
		echo "\n Inside try block"; 
			
		if($var == 0) { 
			throw new Exception('Number is zero.'); 
			echo "\n After throw it will never be executed"; 
		} 
	} 
		
	catch(Exception $e) { 
		echo "\n Exception Caught" . $e->getMessage(); 
	} 
	finally { 
		echo "\n Here cleanup activity will be done"; 
	} 
		
	echo "\n After catch it will be always executed"; 
} 


website(5); 

website(0); 
?> 

Custom Exception Class

<?php 
class myException extends Exception { 
	function get_Message() { 
		
		// Error message 
		$errorMsg = 'Error on line '.$this->getLine(). 
					' in '.$this->getFile() 
		.$this->getMessage().' is number zero'; 
		return $errorMsg; 
	} 
} 

function website($a) { 
	try { 
		if($a == 0) { 
			throw new myException($a); 
		} 
	} 
	
	catch (myException $e) { 
		echo $e->get_Message(); 
	} 
} 

website(5); 
website(0); 
?> 

Web Programming Tutorials Example with Demo

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about PHP Try Catch Exception & Error Handling Tutorial.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.