【发布时间】:2015-06-24 15:59:04
【问题描述】:
我正在使用 Laravel 5.1。
文件类型 jpeg、gif、png 的上传工作正常,但 pdf、doc、docx、txt 文件类型不工作。
这是我的看法
{!! Form::label('department','Department', ['class'=>'col-sm-2 control-label'] ) !!}
<div class="col-sm-10">
{!! Form::select('department', $departmentList, null, ['class'=>'form-control']) !!}
<span style="color: red">{{ $errors->first('department') }}</span>
</div>
<div class="form-group">
{!! Form::label('document','Chose a file or Document', ['class'=>'col-sm-2 control-label'] ) !!}
<div class="col-sm-10">
{!! Form::file('file', null, ['class'=>'form-control']) !!}
<p class="help-block">Upload your document in pdf, doc. jpg, png, tif, gif</p>
<span style="color: red"> {{ $errors->first('file') }}</span>
</div>
</div>
{!! Form::close() !}}
我的表单请求
public function rules()
{
return [
'user_id'=>'integer',
'department'=>'required',
'file'=>'required|mimes:application/msword, application/vnd.openxmlformats-officedocument.wordprocessingml.document, application/pdf, jpeg, png, gif'
];
}
}
和我的控制器
public function update($id, RepositoryRequest $request)
{
$repository = Repository::findOrFail($id);
$repository->department = $request->input('department');
$file = \Input::file('file');
$filename = date('Y-m-d-H:i:s').'-'.$file->getClientOriginalName();
$path =public_path('/img/repository/').$filename ;
\Image::make($file->getRealPath())->resize(468, 249)->save($path);
$repository->file = 'img/repository/'.$filename;
$repository->save();
return redirect('/')->with('flash_message', 'You have successfully updated the repository');
这是错误:
Decoder.php 第 21 行中的 NotReadableException:无法从 文件(/tmp/phpdNQvEG)。
【问题讨论】: