PHP code example of peterson / ultimate-uploader

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

    

peterson / ultimate-uploader example snippets


|--------------------------------------------------------------------------
|This Library uses Image Compressor by can Bachors
|https://github.com/bachors/PHP-Image-Compressor-Class



$upload = new ultimateUploader\ultimateUploader();

or


use \ultimateUploader\ultimateUploader;

$upload = new ultimateUploader();



$upload = new ultimateUploader\ultimateUploader();

$upload = new ultimateUploader\ultimateUploader();
echo $upload->allError;

	//instantiate class
    $upload = new ultimateUploader\ultimateUploader([400]);
	
$upload->run('avatar', 'default', 'upload/avatar', 'images', '1.5mb', 1, ['height' => 500, 'width' => '300'])
    ->error(function($response){

		//you can customize each error text message 
		if($response->data['status'] == 401){
			echo "Custom message - Please select a file to upload";
		}
		elseif($response->data['status'] == 405){
			echo "CUSTOM MSG - {$response->data['message']}";
			return;
		}
		
		//error message
		echo $response->data['message'];
    })->success(function($response){

		//proccess further code blocks
		$response->data;
		
    });

$upload = new ultimateUploader\ultimateUploader();

->success(function($response){

    $response->first();
    This will get all first uploaded data 
    returns as an array
});

$upload = new ultimateUploader\ultimateUploader();

->success(function($response){

    $response->get();
    This will get all uploaded data 
    returns as an array
});

Must be called before the  ->run Method for this to work
Useful for a single file upload like Cover Image or any other single upload

--- Takes just one param (HTML input file name)

//get file data
$width = $upload->getImageAttribute('path_to_img_file);


var_dump($width);


--- returns an assoc array

[
  ["height"]=> int(4209)
  ["width"]=> int(3368)
]