PHP code example of sentgine / file

1. Go to this page and download the library: Download sentgine/file 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/ */

    

sentgine / file example snippets


use Sentgine\File\Filesystem;

// Create a new instance of the Filesystem class
$fileSystem = new Filesystem();

// Set source and destination files
$fileSystem->setSourceFile('path/to/source/file.txt')
           ->setDestinationFile('path/to/destination/file.txt');

// Read content from the source file
$content = $fileSystem->read();

// Update content in the destination file
$fileSystem->update('New content');

// Delete the destination file
$fileSystem->delete();

use Sentgine\File\Filesystem;

// Create a new instance of the Filesystem class
$fileSystem = new Filesystem();

 // Get the content of the file.text file
$content = $filesystem->setSourceFile('/source/directory/file.text')->read();

// Create a new directory if it doesn't exist
$filesystem->createDirectory('/source/new_directory');

// Write the content to the Controller file
$filesystem->setDestinationFile('/source/new_directory/new_file.text')->create($content);

// Replace the content of the destination file
$filesystem->replaceContent(
    replacements: [
       'placeholder1' => 'replacement1',
        'placeholder2' => 'replacement2',
    ]
);