我正在尝试制作一个允许上传文件并将其存储在应用程序的 public/upload 文件夹中的表单。
我的表格是:
<form action="/image/save" method="post">
<input name="image" type="file" />
<input type="submit" value="Save"/>
</form>
和 Controller :
public function save(){
$file = Input::file('image');
$destinationPath = 'upload/';
$filename = $file->getClientOriginalName();
Input::file('image')->move($destinationPath, $filename);
但是当我运行它时,我收到以下错误:
在非对象上调用成员函数 getClientOriginalName()
最佳答案
您需要有一个 file input在表单上启用。 (Doc)
在 Laravel 中,你可以使用:
Form::open('image/save', array('files'=> true))
或
<form action="/images/save" method="post" enctype="multipart/form-data">
否则,您从文件输入中收到的只是文件名作为字符串。
关于php - Laravel 4 上传图片表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16635700/