我一直在编写一个上传脚本,即使我使用的是Laravel内置函数Input :: file(),它仍然会返回null.我要发布我的家庭控制器代码.
public function handleUpload()
{
$user = Auth::user();
$username = $user->username;
$userId = $user->id;
$path_to_users = "users";
$user_profile_img = 'users/'.$username.$userId.'/'.$username.'image001.jpg';
$user_path_profile = "users/$username$userId";
$user_image_name = $username.'image001.jpg';
if(file_exists($path_to_users))
{
if(file_exists("$user_path_profile")){
$file = Input::file('profile')->move("$user_path_profile/", $user_image_name);
} else {
mkdir("$user_path_profile");
$file = Input::file('profile')->move("$user_path_profile/", $user_image_name);
}
} else {
mkdir("users");
mkdir("$user_path_profile");
$file = Input::file('profile')->move("$user_path_profile/", $user_image_name);
}
}
Run Code Online (Sandbox Code Playgroud)
当我死(var_dump(Input :: file('profile')))时返回null,这意味着它基本上不会将我的文件作为实际文件.当我死的时候(var_dump(Input :: get('profile')))它会返回图像名称,这意味着我的上传脚本正在运行但是Laravel后端失败了.这是真的吗,还是我错过了什么?
这是我的HTML表单:
@if($user->id == $userProf->id)
<div class="fileUpload button-success pure-button">
<span>Upload</span>
<form action="{{action('HomeController@handleUpload')}}" method="POST" enctype="multipart/form-data">
<input type="file" name="profile" class="upload" />
</form>
</div> …Run Code Online (Sandbox Code Playgroud)