PHP code example of vulcanphp / filesystem

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

    

vulcanphp / filesystem example snippets



// index.php

use VulcanPhp\FileSystem\File;

 .'/test.txt');

// or, use a helper function
$file = file_handler(__DIR__ .'/test.txt');

// get human format file size
var_dump($file->getBytes());

// get file extension
var_dump($file->getExt());

// get file url
var_dump($file->getUrl());

// move file to another directory
var_dump($file->move(__DIR__ .'/etc/test.txt'));

// remove a file
var_dump($file->remove());

// quick access to file methods
var_dump(File::exists(__DIR__ .'/test.txt'));
var_dump(File::bytes(__DIR__ .'/test.txt'));
var_dump(File::ext(__DIR__ .'/test.txt'));
var_dump(File::move(__DIR__ .'/test.txt', __DIR__ .'/etc/test.txt'));

// ...


// index.php

use VulcanPhp\FileSystem\Folder;

IR__ .'/test');

// or, use a helper function
$folder = folder_handler(__DIR__ .'/test');

// enter to sub folder
$folder->enter('etc');

// get all the files and folder
var_dump($folder->scan());

// remove files within folder
var_dump($folder->delete(['test.txt', 'test2.txt']));

// remove current folder
var_dump($folder->remove());

// quick access to Folder methods
Folder::check(__DIR__ .'/test');
Folder::chmod(__DIR__ .'/test', 0777);
Folder::delete(__DIR__ .'/test', ['text.txt']);
Folder::remove(__DIR__ .'/test');
var_dump(Folder::writable(__DIR__ .'/test'));
var_dump(Folder::scan(__DIR__ .'/test'));

// ...


// index.php

 Folder
storage_init([
    'upload_extensions' => ['png', 'jpg', 'jpeg', 'gif', 'pdf'],
    'max_upload_size'   => 1048576 * 2, // 1048576 = 1 MB
    'upload_dir'        => 'uploads', // make it empty to upload parent folder
]);

// get storage directory uri
var_dump(storage_dir('test.txt'));

// get url from storage directory
var_dump(storage_url('test.txt'));

// download a file from storage 
storage()->download('test.txt');

// download a file with download speed metered
storage()->downloadRate('text.txt', 600); // 600 KB per Second

// download multiple files as a zip
storage()->downloadZip(['test.txt', 'test2.txt'], 'test.zip');

// upload files to storage
storage()->upload(
    // EX: $_FILES['input']
    'input',
    
    // strict: throw error when already exists
    // keep: will keep both files
    // override: will replace previous file
    'strict',
);

// upload file from url
storage()->uploadFromUrl('http://file-location.com');

// ALSO AVAILABLE ALL THE FOLDER METHODS
// enter to a sub folder
storage()->enter('test');

// get all the available files
var_dump(storage()->scan());

// delete files in this sub folder
storage()->delete(['test.txt']);

// back to prevues folder
storage()->back();

// ...


// index.php

use VulcanPhp\FileSystem\Image;

se(__DIR__ . '/test.jpg');

// or, use a helper function
$image = image_handler(__DIR__ . '/test.jpg');

// compress this image
$image->compress(60); // it will compress 60%

// compress and save to another files
$image->compress(60, __DIR__ . '/test-com.jpg');

// resize this image
// width = 520, height = 240
$image->resize(520, 240);

// resize this image and save another file
$image->resize(520, 240, __DIR__ . '/test-thumb.jpg');

// create multiple resizes images 
$image->bulkResize([520 => 240, 360 => 360, 64 => 64]);
// it will create 3 images
// test-520x240.jpg
// test-360x360.jpg
// test-64x64.jpg

// Rotate a Image
$image->rotate(180); // 180 degree

// ...