我一直在寫一個上傳腳本,即使我使用內建函數Input :: file()的Laravel,它仍然返回null。 我打算髮布我的主控制器代碼。輸入:: file()返回null Laravel
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);
}
}
當我死了(的var_dump(輸入::文件(「曲線」)))返回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('[email protected]')}}" method="POST" enctype="multipart/form-data">
<input type="file" name="profile" class="upload" />
</form>
</div>
@endif
你可以在這裏發佈你的上傳表單HTML代碼嗎? –
我想你使用PUT方法上傳,Laravel根本無法處理文件請求,使用POST方法上傳文件。 –