Larave 多图片上传

 

首先使用Dropzone.js前端组件

{{ HTML::style('css/basic.css');}}
{{ HTML::script('js/dropzone.js') }}

form部分只需要

<form action="{{ url('user/upload')}}" class="dropzone" id="my-awesome-dropzone">
<input name="file" type="file" multiple="" />
</form>

laravel部分

public function post_upload(){
	$input = Input::all();
	$rules = array(
		'file' => 'image|max:3000',
	);

	$validation = Validator::make($input, $rules);

	if ($validation->fails())
	{
		return Response::make($validation->errors()->first(), 400);
	}

	$file = Input::file('file');

	$extension = File::extension($file['name']);
	$directory = path('public').'uploads/'.sha1(time());
	$filename = sha1(time().time()).".{$extension}";

	$upload_success = Input::upload('file', $directory, $filename);

	if( $upload_success ) {
		return Response::json('success', 200);
	} else {
		return Response::json('error', 400);
	}
}

完成~~

 

 

参考自http://maxoffsky.com/code-blog/howto-ajax-multiple-file-upload-in-laravel/

 

你可能感兴趣的:(Larave 多图片上传)