看來我的文件上傳不起作用。文件的功能[例如$ file-> getOriginalExtension();]正在返回錯誤。Laravel上傳文件表單無法正常工作
這是我的觀點:
<form class="form-horizontal" method="POST" action="/project/file_post.php" enctype="multipart/form-data">
<---other text inputs--->
Photo: <input type="file" name="photo" />
<input type="submit" class="btn btn-success btn-inline" value="SAVE ">
</form>
控制器:
//code below returns only the filename
$input = Input::all();
$file = array_get($input,'photo');
print_r($file);
//but when using this..it returns an error
$extension = $file->getClientOriginalExtension();
DD($ input)返回:
array:8 [▼
"_token" => "6eScEZe1SLL72JDrQjmBJllNyiHaT8hdGKKMtjsD"
"photo" => "test_test_2016.jpg"
"field2" => "test"
"field3" => "test"
"field4" => "test"
"field5" => "test"
"field6" => "test"
"field7" => "test"
]
難道我做錯了什麼?它返回文件的文件名,但在使用函數時,它返回各種錯誤(例如調用函數getClientOriginalExtension()on string)
您能否請幫忙?謝謝!
附錄:
$photo = $request->file('photo');
echo $photo;
以上代碼也不起作用。沒有錯誤。只返回空白。
add form'action =「post_page.php」;'我認爲它從你的代碼中缺失。提交表單後更改代碼運行的頁面地址。 –
@JeesKDenny,我忘了把它放在我的文章中,但它並沒有在我的實際代碼中丟失。 – Ronald
你不能直接用這個嗎? $ name = Input :: file('photo') - > getClientOriginalName(); – Jaimin