douzhe2981 2014-03-01 15:47
浏览 42
已采纳

Laravel路线表格不起作用

I am trying to upload files to the server, but after i submit the form i always get a Controller method not found error i dont know where am i going wrong. Or if any good tutorial for this purpose?

this is my form

{{ 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() }}

this is my route

Route::post('multiupload', 'ProfileController@multiUpload');

and this is my controller method

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
        }
    }
}
  • 写回答

2条回答 默认 最新

  • dongsunny1113 2014-03-01 22:14
    关注

    Your method should be lowercase change multiUpload() to multiupload() and try again.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 QTOF MSE数据分析
  • ¥15 平板录音机录音问题解决
  • ¥15 请问维特智能的安卓APP在手机上存储传感器数据后,如何找到它的存储路径?
  • ¥15 (SQL语句|查询结果翻了4倍)
  • ¥15 Odoo17操作下面代码的模块时出现没有'读取'来访问
  • ¥50 .net core 并发调用接口问题
  • ¥15 网上各种方法试过了,pip还是无法使用
  • ¥15 用verilog实现tanh函数和softplus函数
  • ¥15 Hadoop集群部署启动Hadoop时碰到问题
  • ¥15 求京东批量付款能替代天诚