PHP code example of iamdual / uploader

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

    

iamdual / uploader example snippets


use iamdual\Uploader;

if (isset($_FILES["file"])) {

    $upload = new Uploader($_FILES["file"]);
    $upload->allowed_extensions(array("png", "jpg", "jpeg", "gif"));
    $upload->max_size(5); // in MB
    $upload->path("upload/files");
    $upload->name("foo");
    
    if (! $upload->upload()) {
        echo "Upload error: " . $upload->get_error();
    } else {
        echo "Upload successful!";
    }
}

use iamdual\Uploader;

if (isset($_FILES["file"])) {
    $upload = (new Uploader($_FILES["file"]))->max_size(20)->path("upload/files")->encrypt_name();
    
    if (! $upload->upload()) {
        echo "Upload error: " . $upload->get_error();
    } else {
        echo "Upload successful!";
    }
}