[英]$request->file return null - Laravel
I tried to upload file from a pc to my Laravel application and store to XAMPP
server. 我试图将文件从PC上传到我的Laravel应用程序,然后存储到
XAMPP
服务器。 Unfortunately, every time when I want to check the file extension using $request->file
it always return me null. 不幸的是,每次当我想使用
$request->file
检查文件扩展名时,它总是返回null。
But when I tried to debug I have seen that file image name that I uploaded from my system. 但是,当我尝试调试时,我看到了从系统上载的文件映像名称。
Here is code from front end: 这是来自前端的代码:
<form action="{{action('CompaniesSettingController@update', $edit_info->id)}}" method="post",enctype="multipart/form-data">
<div class="p-image">
<i class="fa fa-camera upload-button"></i>
<input class="file-upload" name="company_profile" type="file" id="" accept="image/*"/>
</div>
Here Controller code: 此处的控制器代码:
dd($request->all());
$filenameWithExt = $request->file('company_profile')->getClientOriginalName();
Here is what I got from dd
这是我从
dd
得到的
array:12 [▼
"company_profile" => "myimage.jpg"
"name" => "App Name"
"email" => "myapp@gmail.com"
"phone_number" => "12345678"
"company_overview" => "dfsa"
"mission" => "dfs"
"working_evn" => "fgsd"
"company_ach" => "dfsgdfs"
"facebook" => "dfsg"
"linkedin" => "dsf"
"website" => "sdfsfdg"
]
As you can see the file that I have uploaded with named "company_profile" => "myimage.jpg"
. 如您所见,我上传的文件名为
"company_profile" => "myimage.jpg"
。 So, I want to get that image name but it return null and also that file image should be stored in my application and file name I will store in database. 因此,我想获取该图像名称,但它返回null,并且该文件图像应存储在我的应用程序中,并且文件名将存储在数据库中。
Remove the comma after the method="post"
attribute and add space. 删除
method="post"
属性后面的逗号并添加空间。
Change this line: 更改此行:
<form action="{{action('CompaniesSettingController@update', $edit_info->id)}}" method="post",enctype="multipart/form-data">
to 至
<form action="{{action('CompaniesSettingController@update', $edit_info->id)}}" method="post" enctype="multipart/form-data">
And then check the dd($request->all())
to ensure that it is not the string against company_profile. 然后检查
dd($request->all())
以确保它不是针对company_profile的字符串。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.