PHP code example of verot / class.upload.php

1. Go to this page and download the library: Download verot/class.upload.php 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/ */

    

verot / class.upload.php example snippets


$handle = new \Verot\Upload\Upload($_FILES['image_field']);
if ($handle->uploaded) {
  $handle->file_new_name_body   = 'image_resized';
  $handle->image_resize         = true;
  $handle->image_x              = 100;
  $handle->image_ratio_y        = true;
  $handle->process('/home/user/files/');
  if ($handle->processed) {
    echo 'image resized';
    $handle->clean();
  } else {
    echo 'error : ' . $handle->error;
  }
}

use Verot\Upload\Upload;
$handle = new Upload($_FILES['image_field']);

$handle = new \Verot\Upload\Upload($_FILES['image_field']);

$handle = new Upload('/home/user/myfile.jpg');

$handle = new Upload('php:'.$_SERVER['HTTP_X_FILE_NAME']);

$handle = new Upload('php:mycustomname.ext');

$handle = new Upload('data:'.$file_contents);

$handle = new Upload('base64:'.$base64_file_contents);

$handle = new Upload($_FILES['image_field'], 'fr_FR');
$handle = new Upload('/home/user/myfile.jpg', 'fr_FR');

$handle = new Upload($_FILES['image_field']);
header('Content-type: ' . $handle->file_src_mime);
echo $handle->process();
die();

$handle = new Upload($_FILES['image_field']);
header('Content-type: ' . $handle->file_src_mime);
header("Content-Disposition: attachment; filename=".rawurlencode($handle->file_src_name).";");
echo $handle->process();
die();

$handle->allowed   = array('html');
$handle->forbidden = array();
$handle->no_script = false;

echo $handle->log;

$handle->file_new_name_body = 'new name';

$handle->file_name_body_add = '_uploaded';

$handle->file_name_body_pre = 'thumb_';

$handle->file_new_name_ext = 'txt';

$handle->file_safe_name = true;

$handle->file_force_extension = true;

$handle->file_overwrite = true;

$handle->file_auto_rename = true;

$handle->dir_auto_create = true;

$handle->dir_auto_chmod = true;

$handle->dir_chmod = 0777;

$handle->file_max_size = '1024'; // 1KB

$handle->mime_check = true;

$handle->no_script = false;

$handle->allowed = array('application/pdf','application/msword', 'image/*');

$handle->forbidden = array('application/*');

$handle->image_convert = 'jpg';

$handle->image_background_color = '#FF00FF';

$handle->image_default_color = '#FF00FF';

$handle->png_compression = 9;

$handle->webp_quality = 50;

$handle->jpeg_quality = 50;

$handle->jpeg_size = 3072;

$handle->image_interlace = true;

$handle->image_max_width = 200;

$handle->image_max_height = 100;

$handle->image_max_pixels = 50000;

$handle->image_max_ratio = 1.5;

$handle->image_min_width = 100;

$handle->image_min_height = 500;

$handle->image_min_pixels = 20000;

$handle->image_min_ratio = 0.5;

$handle->image_resize = true;

$handle->image_x = 100;

$handle->image_y = 200;

$handle->image_ratio = true;

$handle->image_ratio_crop = true;

$handle->image_ratio_fill = true;

$handle->image_ratio_x = true;

$handle->image_ratio_y = true;

$handle->image_ratio_pixels = 25000;

$handle->image_no_enlarging = true;

$handle->image_no_shrinking = true;

$handle->image_brightness = 40;

$handle->image_contrast = 50;

$handle->image_opacity = 50;

$handle->image_tint_color = '#FF0000';

$handle->image_overlay_color = '#FF0000';

$handle->image_overlay_opacity = 20;

$handle->image_negative = true;

$handle->image_greyscale = true;

$handle->image_threshold = 20;

$handle->image_pixelate = 10;

$handle->image_unsharp = true;

$handle->image_unsharp_amount = 120;

$handle->image_unsharp_radius = 1;

$handle->image_unsharp_threshold = 0;

$handle->image_text = 'test';

$handle->image_text_direction = 'v';

$handle->image_text_color = '#FF0000';

$handle->image_text_opacity = 50;

$handle->image_text_background = '#FFFFFF';

$handle->image_text_background_opacity = 50;

$handle->image_text_font = 4; // or './font.gdf' or './font.ttf'

$handle->image_text_size = 24;

$handle->image_text_angle = 45;

$handle->image_text_x = 5;

$handle->image_text_y = 5;

$handle->image_text_position = 'LR';

$handle->image_text_padding = 5;

$handle->image_text_padding_x = 2;

$handle->image_text_padding_y = 10;

$handle->image_text_alignment = 'R';

$handle->image_text_line_spacing = 3;

$handle->image_auto_rotate = false;

$handle->image_flip = 'h';

$handle->image_rotate = 90;

$handle->image_crop = array(50,40,30,20); OR '-20 20%'...

$handle->image_precrop = array(50,40,30,20); OR '-20 20%'...

$handle->image_bevel = 20;

$handle->image_bevel_color1 = '#FFFFFF';

$handle->image_bevel_color2 = '#000000';

$handle->image_border = '3px'; OR '-20 20%' OR array(3,2)...

$handle->image_border_color = '#FFFFFF';

$handle->image_border_opacity = 50;

$handle->image_border_transparent = '3px'; OR '-20 20%' OR array(3,2)...

$handle->image_frame = 2;

    composer 
php
$handle->image_frame_colors = array('#999999',  '#FF0000', '#666666', '#333333', '#000000');
php
$handle->image_frame_opacity = 50;
php
$handle->image_watermark = 'watermark.png';
php
$handle->image_watermark_x = 5;
php
$handle->image_watermark_y = 5;
php
$handle->image_watermark_position = 'LR';
php
$handle->image_watermark_no_zoom_in = false;
php
$handle->image_watermark_no_zoom_out = true;
php
$handle->image_reflection_height = '25%';
php
$handle->image_reflection_space = 3;
php
$handle->image_default_color = '#000000';
php
$handle->image_reflection_opacity = 60;