Download the PHP package viraj/hawkeye without Composer
On this page you can find all versions of the php package viraj/hawkeye. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download viraj/hawkeye
More information about viraj/hawkeye
Files in viraj/hawkeye
Package hawkeye
Short Description A package for uploading files automatically in a nested md5 hash naming folder structure. A mini CDN for optimized file storage for Laravel.
License MIT
Informations about the package hawkeye
Hawkeye
A Laravel package for uploading files automatically in a nested md5 hash naming folder structure. A mini CDN for optimized file storage for Laravel.
Objective
Normally, we upload a file into a specific folder. In small applications, this is perfectly fine, but in large applications having about thousands of files in a single folder hampers performance. Hawkeye aims to solve this problem. Hawkeye retrieves the uploaded file, creates an unique id and hashes the id with md5. The hashed file is used to create the nested folder structure for the file.
md5 hash of uploaded file => c4ca4238a0b923820dcc509a6f75849b.jpg
The above hashed name will be used to create a directory as
c4c/a42/38a/0b9/238/20d/cc5/09a/6f7/584/c4ca4238a0b923820dcc509a6f75849b.jpg
Installation
In order to install Hawkeye, just add
"viraj/hawkeye": "dev-master"
to your composer.json. Then run composer install
or composer update
.
Then in your config/app.php
add
'Viraj\Hawkeye\HawkeyeServiceProvider',
in the providers array and
'Hawkeye' => 'Viraj\Hawkeye\HawkeyeFacade',
to the aliases
array.
Create Migration
Now generate the Hawkeye migration:
php artisan hawkeye:migration
It will generate the <timestamp>_hawkeye_setup_tables.php
migration. You may now run it with the artisan migrate command:
php artisan migrate
After the migration, one new table will be present:
hawkeye
— stores file records and its meta data
Configuration
You need to publish the configuration for this package to further customize the storage path of files.
Just use php artisan vendor:publish
and a hawkeye.php
file will be created in your app/config
directory.
Configuration file
A typical Hawkeye
configuration file should look like as follows:
Base directory configuration
Setup the base directory in config/hawkeye.php
where your files will be stored.
'hawkeye_base_path' => 'path/to/directory',
For e.g. if you want to have your files in public/images
directory then,
'hawkeye_base_path' => 'images/',
Note: Don't forget the forward slash after images
or if, you want to store them outside public directory, let's suppose in storage/images
, then give the path to directory
'hawkeye_base_path' => '../storage/images/',
Hawkeye will store the files in appropriate directory.
Image Resizing configuration
You can configure Hawkeye to resize uploaded images in various dimensions you require. It comes with some default image dimensions for resizing images according to industry standards, but you are free to configure according to your needs. If you need some different values, edit the values accordingly in config/hawkeye.php
:
'images' => [
'banner' => '1200x800',
'thumbnail' => '300x200',
'large' => '600x500',
],
If you want to stick with above configuration and also add some custom configuration for your app, you can do that as well. Just add the needed dimension and name for your configuration.
'images' => [
'banner' => '1200x800',
'thumbnail' => '300x200',
'large' => '600x500',
'your-configuration' => '800x600',
],
Upload Files using Hawkeye
upload.blade.php
FileController.php
Uploading and resizing files
In your controller, you can write
The above code will upload, resize (to all the image types specified in configuration) and give you a nested array of file names (md5 hashed names):
The above response has 2 parameters:
list
- It has a list of all files that have been uploaded and resized.
separated
- It has a segregated/separated list of all uploaded files and resized images as well, if any!
getList()
If you only want the list of all uploaded and resized files without the data about image type, you can use getList()
method as follows:
The
Resizing for specific image types
Sometimes, you don't want to resize your images in all the types specified in configuration. Don't worry, Hawkeye has a provision for that as well. Specify the name of image types
you want the uploaded images to be resized into in resize()
method and Hawkeye will resize into those types only.
The above code will just resize your images in only 2 types - banner
and large
. The response will be:
generateFullImagePathFor()
This function returns the full image path for a particular file name (hashed) with extension.
Example 1 (Resized image - It has dimesnions appended to the name)
Example 2 (Original image - It has original name)
License
Hawkeye is free software distributed under the terms of the MIT license