This is a package to make AJAX upload process easy and simple! Enhance your customer experience and improve your system performance.
###SEE DEMO
- PHP >=5.3
- Intervention Image (for image processing)
Require this package with composer:
composer require triasrahman/media-upload
After updating composer, add the ServiceProvider to the providers array in config/app.php
'providers' => [
// ...
'Triasrahman\MediaUpload\MediaUploadServiceProvider',
]
Copy the package config to your local config with the publish command:
php artisan vendor:publish
Your HTML form
<input type="file" name="file">
<img clas="preview" src="">
Using jQuery AJAX
$('input[name=file]').change(function()
{
// AJAX Request
$.post( '/media-upload', {file: $(this).val()} )
.done(function( data )
{
if(data.error)
{
// Log the error
console.log(error);
}
else
{
// Change the image attribute
$( 'img.preview' ).attr( 'src', data.path );
}
});
});
Edit media-upload.php
for more configurations.
/*
|--------------------------------------------------------------------------
| Upload Types
|--------------------------------------------------------------------------
|
| It's the flexibility of this package. You can define the type of upload
| file methods. For example, you want to upload for profile picture,
| article post, background, etc. Here is
|
*/
'types' => [
// ... put your custom type ...
'profile' => [
'middleware' => 'auth',
'format' => 'image',
'image' => [
'fit' => [400, 400],
'thumbs' => [
'small' => [50, 50],
'medium' => [100, 100],
]
],
'save_original' => true,
],
'profile-cover' => [
'middleware' => 'auth',
'format' => 'image',
'image' => [
'fit' => [1200, 400],
],
'multiple' => false,
],
'media' => [
'middleware' => 'auth',
'format' => 'image|video|audio',
'image' => [
'thumbs' => [
'small' => [50, 50],
'medium' => [100, 100],
]
],
'multiple' => true,
],
],
Coming Soon
Laravel Media Upload is licensed under the MIT License.
Copyright 2015 Trias Nur Rahman