Topic: Technology

Laravel 6 Delete File from public folder Example 0

Laravel 6 Delete File from public folder

Today, We want to share with you Laravel 6 Delete File from public folder.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 file from public folder in laravel 6 with an example.

Laravel 6 Delete File from public folder

There are the Following The simple About Laravel 6 Delete File from root folder Full Information With Example and source code.

As I will cover this Post with live Working example to develop laravel 6 delete image from storage folder, so the Laravel 6 check if folder exists before create directory is used for this example is following below.

laravel 6 remove file from public folder

We simple step to create a image upload functionality as well as put that main image on our root upload directory.

Using File System:

public function deleteImage()
{  
  if(\File::exists(public_path('movies/tamilrokers.png'))){
    \File::delete(public_path('movies/tamilrokers.png'));
  }else{
    dd('Sorry, Your File does not exists.');
  }
}

laravel 6 remove file from storage public folder

Using Storage System:

public function deleteImage()
{  
  if(\Storage::exists('movies/tamilrokers.png')){
    \Storage::delete('movies/tamilrokers.png');
  }else{
    dd('Sorry, Your File does not exists.');
  }
}

how to remove file from folder in laravel 6

Using Core PHP:

public function deleteImage()
{  
    if(file_exists(public_path('movies/tamilrokers.png'))){
      unlink(public_path('movies/tamilrokers.png'));
    }else{
      dd('Your File does not exists, Sorry!.');
    }

}

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 Laravel6 Delete File from public folder.
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.

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.