我正在尝试将文件上传到服务器,但在我提交表单后,我总是得到一个未找到的控制器方法错误我不知道我哪里出错了。 或者,如果有任何好的教程用于此目的?
这是我的表格
{{ Form::open(array('files' => true , 'action' => array('ProfileController@multiUpload' ))) }}
{{ Form::file('file[]', array('multiple'=>true))}}
{{ Form::hidden('folder', $data->username) }}
{{ Form::submit('Upload To Gallery') }}
{{ Form::close() }}
这是我的路线
Route::post('multiupload', 'ProfileController@multiUpload');
这是我的控制器方法
class ProfileController extends BaseController
{
public function multiUpload()
{
if (Input::hasFile('file[]'))
{
$all_uploads = Input::file('file[]');
$folder = Input::get('folder');
// Make sure it really is an array
if (!is_array($all_uploads))
{
$all_uploads = array($all_uploads);
}
$error_messages = array();
// Loop through all uploaded files
foreach ($all_uploads as $upload)
{
// Ignore array member if it's not an UploadedFile object, just to be extra safe
if (!is_a($upload, 'Symfony\Component\HttpFoundation\File\UploadedFile'))
{
continue;
}
$validator = Validator::make(
array('file' => $upload),
array('file' => 'required|mimes:jpeg,png|image|max:5000')
);
if ($validator->passes())
{
Image::upload($upload, 'uploads/'.$folder , true);
}
else
{
// Collect error messages
$error_messages[] = 'File "' . $upload->getClientOriginalName() . '":' . $validator->messages()->first('file');
}
}
// Redirect, return JSON, whatever...
return $error_messages;
}
else
{
// No files have been uploaded
}
}
}
答案 0 :(得分:0)
可能错误是由BaseContoller错误拼写引起的
更改
class ProfileController extends Basecontroller
到
class ProfileController extends BaseController
答案 1 :(得分:0)
您的方法应该是小写更改multiUpload()
到multiupload()
,然后重试。