简体   繁体   English

Laravel和jQuery文件上传

[英]Laravel and jQuery file upload

Im trying to add jQuery file upload plugin https://github.com/blueimp/jQuery-File-Upload/wiki/Basic-plugin to my site and im using Laravel framework. 我试图将jQuery文件上传插件https://github.com/blueimp/jQuery-File-Upload/wiki/Basic-plugin添加到我的网站,并使用Laravel框架。

This is in my view: 我认为这是:

            {{ Form::open(['action' => 'MyController@uploadGallery'])}}

                {{ Form::text('name')}} <br><br>

                <input id="fileupload" type="file" name="files[]" data-url="server/php/" multiple>
                <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
                <script src="theme-admin/fileupload/js/vendor/jquery.ui.widget.js"></script>
                <script src="theme-admin/fileupload/js/jquery.iframe-transport.js"></script>
                <script src="theme-admin/fileupload/js/jquery.fileupload.js"></script>

                <script>
                $(function () {
                    $('#fileupload').fileupload({

                        url: '/gallery',
                        dataType: 'json',
                        done: function (e, data) {
                            $.each(data.result.files, function (index, file) {
                                $('<p/>').text(file.name).appendTo(document.body);
                            });
                        },

                        progressall: function (e, data) {
                            var progress = parseInt(data.loaded / data.total * 100, 10);
                            $('#progress .bar').css(
                                'width',
                                progress + '%');
                        }

                    });

                });
                </script>

                <br>

                <input type="submit">

            {{ Form::close() }}

            <div id="progress">
                <div class="bar" style="width: 0%;"></div>
            </div>

After selecting images some javascript is calling path: *website*/server/php where is index.php, but Laravel is redirecting that path, returning error: net::ERR_TOO_MANY_REDIRECTS . 选择图像后,一些javascript调用了路径: *website*/server/php ,其中index.php,但是Laravel重定向了该路径,并返回错误: net::ERR_TOO_MANY_REDIRECTS I've tryed to add new route and copypaste script in index.php to MyController@serverphp method, but the same error occured: 我试图在index.php中将新的路由和copypaste脚本添加到MyController @ serverphp方法中,但是发生了相同的错误:

Route::get('server/php', array('as' => 'serverphp', 'uses' => 'MyController@serverphp'));

What should I do now? 我现在应该怎么办?

I had this same issue, might not be the exact same problem, but on the project I'm working one, there was a rule on .htaccess to redirect urls based on trailing slashes. 我遇到了同样的问题,可能不是完全相同的问题,但是在我正在工作的项目上,.htaccess上有一条规则,即基于尾部斜杠重定向URL。 That might got in conflict with the jquery upload redirect rule. 这可能与jquery上传重定向规则冲突。 As soon as I removed that rule everything worked fine. 我删除该规则后,一切正常。

# Redirect Trailing Slashes...
#RewriteRule ^(.*)/$ /$1 [L,R=301]

I realized that it should had been something related to .htaccess because I just installed the default example on my local computer and it worked. 我意识到它应该与.htaccess有关,因为我只是在本地计算机上安装了默认示例,并且它可以工作。 When I upload the default example to the server it didn't work. 当我将默认示例上传到服务器时,它不起作用。 It got the redirect loop. 它得到了重定向循环。 Thus, it was probably a server configuration issue. 因此,这可能是服务器配置问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM