【问题标题】:How to use Dropzone with laravel 4.2如何在 laravel 4.2 中使用 Dropzone
【发布时间】:2015-06-03 14:24:01
【问题描述】:

我想使用 Laravel 4.2 将“Dropzone”合并到我的网站中,我在他们的官方网站 here 中找到了一个示例。

但是当我将它添加到我的表单时,表单会改变行为,我无法在控制器中处理图像。你能给我一个使用 Laravel 4.2 的 dropzone 的基本示例吗?

【问题讨论】:

    标签: laravel laravel-4 dropzone.js


    【解决方案1】:
    <script>
                            var myDropzone = new Dropzone("div#dropzone", {
                                url: "{{URL::route('compose-attachment')}}",
                                //clickable: "#yourSubmitButton",
                                paramName: "file",
                                addRemoveLinks: true,
                                init: function() {
    
                                            });
                                        });
                                }
                            });
                        </script>
    

    路线:

    Route::post('/compose-attachment', array( 'as' => 'postMsgAttachment','uses' => 'UserController@getPostAttachment'));
    

    控制器:

    public function getPostAttachment(){
    
    
     $file = Input::file('file');
     $destinationPath =  public_path().'/uploads';
     $time = time();
    
     $filename = $time."-".$file->getClientOriginalName(); 
     $upload_success = Input::file('file')->move($destinationPath, $filename);
     }
    

    【讨论】:

    • 我收到此错误(未定义路由 [/compose-attachment]。)
    • 你的控制器也叫UserController吗?
    • ArticleController,但我将路由重命名为:Route::post('/compose-attachment', array('as' => 'postMsgAttachment','uses' => 'ArticleController@getPostAttachment') );
    • 你应该有两条路由: Route::post('/compose-attachment', array( 'as' => 'postMsgAttachment','uses' => 'ArticleController@getPostAttachment'));发布 dropzone 文件。和一个 get Route 来呈现您的视图。控制器也是如此。在您的控制器中,您应该有两个函数,一个是两个渲染视图,即您的“get”路由,第二个函数用于“post”路由
    • 是的,我有两条路线,能否请您也给我表单代码(包含 drapzone div 的表单)
    【解决方案2】:

    这是我的查看代码:

    {{ Form::open(array('files'=> true  , 'method' => 'post' ,'route' => array('article.create', Route::current()->getParameter('lang')))) }}
    
                      <div class="fallback" id = "dropzone" >
                        <input name="file" type="file" multiple />
                      </div>
    
            {{ Form::submit(Lang::get('messages.create') , array('class' => 'btn btn-default custom-submit')) }}
    
        {{ Form::close() }}
    <script>
    var myDropzone = new Dropzone("div#dropzone", {
        url: "{{URL::route('compose-attachment')}}",
        //clickable: "#yourSubmitButton",
        paramName: "file",
        addRemoveLinks: true,
        init: function() {
    
                    });
                });
        }
    });
    </script>
    

    路线:

    Route::post('/compose-attachment', array( 'as' => 'postMsgAttachment','uses' => 'ArticleController@getPostAttachment'));
    

    控制器:

    public function getPostAttachment(){
            $file = Input::file('file');
            return var_dump($file);
        }
    

    【讨论】:

      猜你喜欢
      • 2018-03-12
      • 1970-01-01
      • 2014-05-10
      • 2020-12-11
      • 1970-01-01
      • 2011-12-08
      • 1970-01-01
      • 2018-06-14
      • 1970-01-01
      相关资源
      最近更新 更多