Package Data | |
---|---|
Maintainer Username: | edenreich |
Maintainer Contact: | eden.reich@gmail.com (Eden Reich) |
Package Create Date: | 2016-02-01 |
Package Last Update: | 2019-02-24 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-17 03:05:59 |
Package Statistics | |
---|---|
Total Downloads: | 132 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 10 |
Total Watchers: | 3 |
Total Forks: | 5 |
Total Open Issues: | 1 |
with composer just run:
composer require reich/upload
or
You can also download src/Upload.php and simply use it.
This class is fully integrated into laravel framework using Laravel Auto-Discovery. If you don't use v5.5+ you may import the necessary files path in your /config/app.php file manually:
...
"providers" => [
/*
* Package Service Providers...
*/
Reich\Upload\Laravel\UploadServiceProvider::class,
],
"aliases" => [
"Upload" => Reich\Upload\Laravel\UploadFacade::class,
]
...
Make sure the form is submitted:
if(Upload::submitted())
{
// rest of the code goes here
}
Make an instance of the class
$upload = new Upload(YOUR-HTML-INPUT-NAME);
Set the directory where you want to upload the files, by default it will upload to your main directroy
$upload->setDirectory('img/');
You may also specify that you want to create this directory if it's not exists
$upload->setDirectory('img/')->create(true);
You can set the rules you want for your upload using the following syntax:
$upload->addRules([
'size' => 2000,
'extensions' => 'png|jpg|pdf'
]);
or
$upload->addRules([
'size' => 2000,
'extensions' => ['png', 'jpg', 'pdf']
]);
Set this only if you want to have a encrypt file names(optional for security):
$upload->encryptFileNames(true);
You may also specify that you want only certain file type to be encrypted like so:
$upload->encryptFileNames(true)->only(['jpg']); // only jpg files will be encrypted
Or also the following syntax:
$upload->encryptFileNames(true)->only('jpg|png|txt'); // only jpg, png and txt files will be encrypted
After all is set just run the following command
$upload->start();
Whenever a file has been successfully uploaded.
$upload->success(function($file) {
// handle the file
});
If something went wrong listen to error.
$upload->error(function($file) {
// handle the file
});
Check wether there are errors and if there arent errors, proccess the upload:
if($upload->unsuccessfulFilesHas())
{
// display all errors with bootstraps
$upload->displayErrors();
// now of course you may formating it differently like so
foreach($upload->errorFiles as $file)
{
// do whatever you want with the file object
// - $file->name
// - $file->encryptedName *only if you asked to encrypt*
// - $file->type
// - $file->extension
// - $file->size
// - $file->error
// - $file->errorMessage
}
}
else if($upload->successfulFilesHas())
{
$upload->displaySuccess();
// now of course you may formating it differently like so
foreach($upload->successFiles as $file)
{
// do whatever you want with the file object
// - $file->name
// - $file->encryptedName *only if you asked to encrypt*
// - $file->type
// - $file->extension
// - $file->size
}
}
print_r($upload->debug()); // There are some errors only you should look at while setting this up