triasrahman/media-upload

此包已被 废弃 并不再维护。没有建议的替代包。

为 Laravel 简单易用的 AJAX 媒体上传

v1.0.3 2015-06-12 19:12 UTC

This package is not auto-updated.

Last update: 2020-08-21 20:25:35 UTC


README

Build Status Total Downloads Latest Stable Version License

这是一个使 AJAX 上传过程变得简单和简单的包!增强客户体验并提高系统性能。

###查看演示

要求

安装

使用 composer 需要此包

composer require triasrahman/media-upload

更新 composer 后,将 ServiceProvider 添加到 config/app.php 中的 providers 数组

'providers' => [
	//	...
	'Triasrahman\MediaUpload\MediaUploadServiceProvider',
]

使用发布命令将包配置复制到本地配置

php artisan vendor:publish

使用

您的 HTML 表单

<input type="file" name="file">
<img clas="preview" src="">

使用 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 );
			}
		});
});

配置

编辑 media-upload.php 进行更多配置。

/*
 |--------------------------------------------------------------------------
 | 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,
	],

],   

前端集成

即将推出

许可

Laravel Media Upload 采用 MIT 许可 许可。

版权所有 2015 Trias Nur Rahman