PHP code example of lazarusphp / openhandler

1. Go to this page and download the library: Download lazarusphp/openhandler library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

lazarusphp / openhandler example snippets


composer install lazarusphp/openhandler


// Setting a path within the methods parameters will set the directory root.
// Leaving it blank will default to the folder root.
$filehandler = OpenHandler::create("/var/www/OpenHandler/Structure");

// Make Sure path exists
$filehandler->directory("/Apps/Login");

$filehandler->list("/Apps");

foreach($filehandler->list("/Apps") as $item => $folders)
{
    // List code goes here.
}

$filehandler->delete("/Apps/Home/users.env");

$filehandler->delete("/Apps");


$filehandler->prefix("/App/Users",function($handler){
    // Use handler at this point to call methods
    $handler->directory("/Uploads");
    if(isset($_POST["file"]) && $_SERVER["REQUEST_METHOD"] === "POST")
    {
        // Set the path and the Form Name value.
        $handler->upload("Uploads","file");
    }
})



if(isset($_POST["file"]) && $_SERVER["REQUEST_METHOD"] === "POST")
{
    $filehandler->upload("/uploads/Path","file"); 
}



use LazarusPhp\OpenHandler\CoreFiles\Traits\Structure;

use Structure;

    if($this->hasFile("/App/Home/test.php"))
    {
        echo "this is a valid File";
    }

    if($this->fileExists("App/Home/test.php"))
    {
        echo "file Exists";
    }

if($this->hasDirectory("/Apps/Home"))
{
    echo "directory Exists";
}
else
{
    echo "Directory doesnt exist";
}

$class = $this->reflection(__CLASS__);
$class->getShortName();

$this->getExtension("/App/Home/Users.php");

    if($this->hasExtension("/App/Home/test.php","php"))
    {
        echo "FIle is a valid type";
    }


function myCustommFileMethod($file)
{
    $extention = $this->getExtension($file);
    if($this->whitelistExtension($extension,["php","js","txt"]))
    {
        echo "We can Continue";
    }
}

$filemethod = new CustomClass();
$filemethod->myCustomFileMethod("App/Home/Users.php");