所以我想在我的视图中上传和播放视频,但是当我尝试上传视频.mp4时,我收到此错误,我不知道它是否会在我的视图中播放。当我尝试上传视频时,我收到此错误。在非对象上调用成员函数getRealPath()
我该怎么办?我的意思是我如何上传视频并播放我的观点.blade.php
所以这是我的控制器上传图片/视频
$image = Input::file('image');
var_dump($image->getRealPath());
$filename = $image->getClientOriginalName();
//saving image to public folder
Image::make($image->getRealPath())->resize('150', '150')->save('public/img/' .$filename);
$users = Auth::user();
//saving image to database
$post = new Post();
$post->title = Input::get('title');
$post->content = nl2br(Input::get('content'));
$post->image = $filename;
$users->post()->save($post);
return Redirect::route('profile', array('id' => $users->id));
这是我的view.blade.php,我上传文件
@section('content')
<div class="create-post">
{{Form::open(array('url' => 'Newpost', 'files' => 'true', 'method' => 'post'))}}
{{Form::label('title', 'Title')}}
{{Form::text('title')}}<br>
{{Form::label('content', 'Content')}}
{{Form::textarea('content')}}
<br>
{{Form::file('image')}}
{{Form::submit('Publish')}}
{{Form::close()}}
</div>
@stop
答案 0 :(得分:0)
如果您上传的文件大于upload_max_filesize
post_max_size
php.ini
,那么Input :: file('image')将返回null,以获得此尝试的解决方法首先评估if是否为null:
<?php
$image = Input::file('image');
if($image) {
var_dump($image->getRealPath());
$filename = $image->getClientOriginalName();
//saving image to public folder
Image::make($image->getRealPath())->resize('150', '150')->save('public/img/' .$filename);
$users = Auth::user();
//saving image to database
$post = new Post();
$post->title = Input::get('title');
$post->content = nl2br(Input::get('content'));
$post->image = $filename;
$users->post()->save($post);
return Redirect::route('profile', array('id' => $users->id));
}
然后,如果null显示错误消息。
这有效,但强烈建议在代码中实现file size validation。
我希望能为你做好准备。