[英]DropzoneJs Call to a member function getClientOriginalExtension() on null
在开始解释我的问题之前,我不得不说我在该站点上阅读了很多主题,其中大多数主题都与
enctype
有关,但是我的表格中也包含了该主题。
我at least in dropzone box view
上传照片at least in dropzone box view
但不会出现错误。 但是一旦我点击保存按钮,我会得到
"Call to a member function getClientOriginalExtension() on null"
这是我的form
{{ Form::open(array('route' => 'dropzone.store', 'method' => 'post', 'files' => true, 'class' => 'dropzone', 'id' => 'my-awesome-dropzone')) }}
<div class="fallback">
<input name="file" type="file" multiple />
</div>
<input name="imageable_id" type="hidden" value="{{$product->id}}" />
<div class="clearfix"></div>
{{ Form::submit('Create Product', array('class' => 'btn btn-success')) }}
{{Form::close()}}
我的controller
public function dropzoneStore(Request $request)
{
$productID = $request->imageable_id;
$product = Product::findOrFail($productID);
// works
$file = $request->file('file');
$filename = 'product' . '-' . str_random(10) . '.' . $file->getClientOriginalExtension();
$filePath = public_path('images/');
$request->file('file')->move($filePath, $filename);
return Image::create([
'name' => $filename,
'imageable_id' => $productID,
]);
}
PS:错误来自$filename = 'product' . '-' . str_random(10) . '.' . $file->getClientOriginalExtension();
$filename = 'product' . '-' . str_random(10) . '.' . $file->getClientOriginalExtension();
我在console
on success
结果:
{"name":"product-oQPyBfyZDK.jpg","imageable_id":"3","updated_at":"2018-02-07 16:30:17","created_at":"2018-02-07 16:30:17","id":13}
我将controller
代码放入if语句中,例如:
if ($request->hasFile('file'))
{
$file = $request->file('file');
$filename = 'product' . '-' . str_random(10) . '.' . $file->getClientOriginalExtension();
$filePath = public_path('images/');
$request->file('file')->move($filePath, $filename);
}
现在我得到这个错误:
未定义的变量:文件名
在:
return Image::create([
'name' => $filename,
'imageable_id' => $productID,
]);
任何想法?
我将退货放进去,如果它能正常工作,请查看我的更新部分以获取更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.