fknussel/image-uploader

A simple and elegant PHP library for uploading and serving images

v1.2.0 2016-05-04 14:23 UTC

This package is not auto-updated.

Last update: 2024-05-17 16:50:31 UTC


README

A simple yet elegant PHP library for uploading and serving images. The aim of this project is to act as an interface to image uploading and serving on a media server.

Prerequisites

  1. Successfully tested on PHP >= 5.5
  2. GD is required (sudo apt-get install php5-gd will do)

Installation using Composer

Add the following dependency to your composer.json file:

{
  "require": {
    "fknussel/image-uploader": "dev-master"
  }
}

Fetch the dependecy by running:

php composer.phar install

Finally, import image-uploader into your script:

require("vendor/autoload.php");

Usage

Serving images

try {
  $imageUploader = new ImageUploader(UPLOAD_DIR, MD5_HASH_SALT);
  $res = $imageUploader->serve($_GET["identifier"]);
  var_dump($res);
} catch (Exception $e) {
  var_dump($e);
}

Uploading images

try {
  $imageUploader = new ImageUploader();
  $imageUploader->setPath(UPLOAD_DIR);
  $imageUploader->setSalt(MD5_HASH_SALT);
  $imageUploader->setMaxFileSize(MAX_FILE_SIZE);

  $uid = time() . rand();
  $success = $imageUploader->upload($_FILES[INPUT_FIELD_NAME], $uid);

  echo json_encode(array("success" => $success));
} catch (Exception $e) {
  die($e);
}

License

image-uploader is MIT licensed.

This project is a somewhat modified version of Dhaval Kapil's image-uploader.