learncodeweb/filesupload

A very simple (GD library Image processing) class for upload multiple files. You can create multiple thumbnails, add watermark (text/image), resize and change the quality of the images. You can also use this class with any PHP framework, tested with Laravel 8 and Laravel 9.

dev-main 2024-09-18 02:02 UTC

This package is auto-updated.

Last update: 2024-11-18 02:20:52 UTC


README

A PHP base class that you can use to upload any file into the server. It is a very lightweight class and highly customizable. You can use this class with any framework or with core PHP.

GitHub GitHub file size in bytes Packagist Downloads GitHub repo size

Donate with love Donate with love

Dependencies:

This class is based on the GD library for image processing. If you don’t have this library install it or enable it in php.ini. To install the GD library use the below command.

sudo apt-get install php-gd

After installation makes sure you have a gd.ini file then open the php.ini file and find it below.

;extension=gd

Remove the comment [ ; ] and change it to below.

extension=gd

Composer installation:

composer require learncodeweb/filesupload:dev-main

After installation recreates the autoload file with the help of the below command.

composer dump-autoload

How to import into the project:

In laravel 8+ (Tested)

use anyFileUpload\FilesUploadAndImageResize as anyFilesUpload;

$files = new anyFilesUpload('array', ['jpg', 'jpeg', 'png'], public_path('uploads'), 0777);
$files->uploadFiles('files', 250, [], '', 100, '850', ['350']);

dd($files->uploadedData);

In core PHP just add the autoload.php file to your project like below.

required('.../vendor/autoload.php');
$upload    =    new anyFileUpload\ImageUploadAndResize('array', ['jpeg', 'jpg', 'png'], '../uploads', 0655);
$upload->uploadFiles('files', 250, '', $rename, 100, '850', ['350','450']);

Class option & features:

A PHP base class that you can use to upload any file into the server. It is a very lightweight class and highly customizable. You can use this class with any framework or with core PHP.

  1. Upload Single Or Multiple Files.
  2. Upload Any Type Of Files (Not Only Images).
  3. The image file can Resize.
  4. Create Image Thumbnails (With Keep The Image Aspect Ratio).
  5. You can add a watermark (Text, Image).
  6. Easy Integration With Forms.
  7. Create Any Number Of Thumbnails Under One Upload.
  8. Customizable Paths To Thumbnails Folders.
  9. Customizable Thumbnails Sizes And Dimensions.
  10. Files Extension Filters.
  11. File Size Limit for Uploading.

All parameters that you need to set in the constructor

All parameters that you need to set in the method

How to use with direct access:

require('../FilesUploadAndImageResize.php'); // File direct access
$rename    =    rand(1000, 5000) . time(); // left empty if you want the real file name
$upload    =    new anyFileUpload\ImageUploadAndResize('array', ['jpeg', 'jpg', 'png'], '../uploads', 0655);
$upload->uploadFiles('files', 250, '', $rename, 100, '850', ['350','450']);

For watermark you will use an array and be able to add the image as a watermark or text.

With text below will be the parameters:

[
    'value' => "HI I AM ZAID",
    'font-size' => 50,
    'font-family' => "../fonts/Myriad-Pro-Regular.ttf",
    'font-color' => '#0a103e',
    'position-x' => 400,
    'position-y' => 100
];

With the image below will be the parameters:

[
    'value' => "your-image-complete-path",
    'position-x' => 400,
    'position-y' => 100
];

The response will get like the below:

In the below response, you will get the uploaded/not uploaded/bad extensions and success/error flags array or JSON data.

print "<pre>";
print_r($upload->uploadedData);
print "</pre>";

Upload file size change on the server

There is a possibility the upload file size is not set on a server, the default 2MB value is set on a server. If you face this type of issue just find the right path of your php.ini file and change the bleow two parameters.

upload_max_filesize = 2M
post_max_size = 8M

Change to below.

upload_max_filesize = 100M
post_max_size = 150M

Remember:

post max size should be greater than upload max filesize.

Donate with love Donate with love