RT:如何在文章中插入多长图片
例如本站里的评论区里面可以添加图片,我想做的是在创建文章的时候插入图片。我一开始是按照这上面的教程来写的Howto : AJAX multiple file upload in Laravel,用的是@JellyBool 跟我说的http://www.dropzonejs.com/ 这个网站的内容。
在admin/ArticlesContronller
里面加了教程上的一段代码:
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);
}
}
因为一开始想测试一下所以一开始代码并没有写进内容里面:
@extends('app')
@section('content')
<div class="container">
<div class="row">
<div class="col-md-10 col-md-offset-1">
<div class="panel panel-default">
<div class="panel-heading">新增 Article</div>
<div class="panel-body">
@if (count($errors) > 0)
<div class="alert alert-danger">
<strong>Whoops!</strong> There were some problems with your input.<br><br>
<ul>
@foreach ($errors->all() as $error)
<li>{ $error }</li>
@endforeach
</ul>
</div>
@endif
<form action="{ url('admin/articles/upload')}" class="dropzone" id="my-awesome-dropzone"></form>
{!! Form::open(['url'=>'admin/articles/store']) !!}
<div class="form-group">
{!! Form::label('title','标题:') !!}
{!! Form::text('title',null,['class'=>'form-control']) !!}
</div>
<div class="form-group editor">
@include('editor::head')
{!! Form::label('content','正文:') !!}
{!! Form::textarea('content',null,['class'=>'form-control','id'=>'myEditor']) !!}
</div>
<div class="form-group">
{!! Form::label('published_at','发布日期') !!}
{!! Form::input('date','published_at',date('Y-m-d'),['class'=>'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('tag_list','选择标签') !!}
{!! Form::select('tag_list[]',$tags,null,['class'=>'form-control js-example-basic-multiple','multiple'=>'multiple']) !!}
</div>
<div class="form-group">
{!! Form::submit('发表文章',['class'=>'btn btn-success form-control']) !!}
</div>
{!! Form::close() !!}
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
$(".js-example-basic-multiple").select2({placeholder: "添加标签"});
</script>
@endsection
其中<form action="{ url('admin/articles/upload')}" class="dropzone" id="my-awesome-dropzone"></form>
就是上传图片的代码,结果(因为图片比较好说明,所以上传图片了):
出现了一些网页代码,而且那个勾和×都点击不了。
第一个是上传的问题,第二个是怎样可以直接在
<div class="form-group editor">
@include('editor::head')
{!! Form::label('content','正文:') !!}
{!! Form::textarea('content',null,['class'=>'form-control','id'=>'myEditor']) !!}
</div>
插入图片?
最后真诚感谢@JellyBool 最近多次相助,图片上传弄了3天弄不出来,昨天Jelly跟我说http://www.dropzonejs.com/ 图片上传的,但是弄了好久又弄不出来,是在没办法,又写贴求助。