Php Laravel 5.6:对字符串调用成员函数getRealPath()
我正试图发送一封电子邮件,其中包含我在Laravel中的项目中的一个文件,但我在字符串上调用成员函数getRealPath()时遇到此错误 这是我的Php Laravel 5.6:对字符串调用成员函数getRealPath(),php,laravel,laravel-5,Php,Laravel,Laravel 5,我正试图发送一封电子邮件,其中包含我在Laravel中的项目中的一个文件,但我在字符串上调用成员函数getRealPath()时遇到此错误 这是我的存储功能: public function store(Request $request) { $data = array( 'destino' => $request['destino'], 'asunto' => $request['asunto'], 'con
存储
功能:
public function store(Request $request)
{
$data = array(
'destino' => $request['destino'],
'asunto' => $request['asunto'],
'contenido' => $request['contenido'],
'a_file' => $request['a_file']
);
Mail::send('administracion.email.email_body', $data, function($message) use ($data)
{
$message->to($data['destino']);
$message->subject($data['asunto']);
$message->from(Config::get('mail.username'));
$message->attach($data['a_file']->getRealPath(), array(
'as' => 'a_file' . $data['a_file']->getClientOriginalExtension(),
'mime' => $data['a_file']->getMimeType())
);
});
return Redirect::to('email');
}
看起来,
$request['a_file']
为您提供了一个字符串,而不是一个上传的文件
实例。您的表单支持文件上传吗
使用laravelcollective Form facade添加此项的方法是在如下选项中传递'files'=>true
:
{!!Form::open(['url'=>route('myRoute'),'method'=>post','files'=>true])!!
或者,如果未使用表单帮助器,请按如下方式设置enctype
html属性:
我刚刚添加了enctype,它工作得很好。我得到了这个文件名:a_datatxt,我的意思是,在名称文件和扩展名之间没有一个点,你在a_文件
和扩展名之间没有连接'as'=>'a_文件'$data['a_file']->getClientOriginalExtension()
上面应该是这样的,注意a_文件后的点:'as'=>“a_文件”$数据['a_file']->getClientOriginalExtension()