PHP code example of codad5 / file-helper

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

    

codad5 / file-helper example snippets



    $file_upload_controller = new Codad5\FileHelper\FileUploader('test', "uploads/");

#any other extension aid the given will give error or ignored depending on your error settings
$file_upload_controller->add_ext('svg', 'png');

# for unique id can be replaced with uniqid('', true)
$file_upload_controller->set_prefix('my prefix');

$file_upload_controller->set_sizes(10000, 20);

/**
 * This is use to turn on and off reporting of the upload process
 * @param bool $file_error - to report error imbound in file from request if `true` else ignore
 * @param bool $size_error - TO report size related error if `true` else ignore
 * @param bool $type_error - To report error related to file type if `true` else ignore
 */
$file_upload_controller->set_reporting(true, false, true);


$file_upload_controller->move_files();



$upload_path = $file_upload_controller->get_uploads();

foreach ($upload_path as $key => $value) {
        # code...
        echo "This file has been uploaded to ".$value['uploaded_path']."<br/>;
    }



$file_upload_controller = new \Codad5\FileHelper\FileUploader('tes', "uploads/");

    $uploaded_file_array = $file_upload_controller
    ->set_reporting(false, false, false)
    ->add_ext('png', 'pdf')
    ->set_prefix('cool Stuff')
    ->move_files()
    ->get_uploads();

    foreach ($uploaded_file_array as $key => $value) {
        # code...
        echo "This file has been uploaded to ".$value['uploaded_path']."<br/>";
    }