【发布时间】:2016-07-28 03:46:11
【问题描述】:
我的文件上传似乎无法正常工作。文件的函数 [例如 $file->getOriginalExtension();] 正在返回错误。
这是我的看法:
<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())
你能帮忙吗?谢谢!
附录:
$photo = $request->file('photo');
echo $photo;
上面的代码也不起作用。没有错误。只返回空白。
【问题讨论】:
-
添加表单
action="post_page.php";我认为您的代码中缺少它。修改提交表单后代码运行的页面地址。 -
@JeesKDenny,我忘了把它放在我的帖子中,但我的实际代码中并没有丢失它。
-
不能这样直接使用吗? $name = Input::file('photo')->getClientOriginalName();
标签: php file upload laravel-5.2