代码之家  ›  专栏  ›  技术社区  ›  Kiriakos Grhgoriadhs

403禁止通过AJAX上传图像

  •  -1
  • Kiriakos Grhgoriadhs  · 技术社区  · 7 年前

    我试图找到解决我的问题的方法,同时我试图通过AJAX上传图像。

    我正在使用此代码:

    document.getElementById('file').addEventListener('change', function(e) {
            var file = this.files[0];
            console.log(file);
            var xhr = new XMLHttpRequest();
            (xhr.upload || xhr).addEventListener('progress', function(e) {
                var done = e.position || e.loaded
                var total = e.totalSize || e.total;
                console.log('xhr progress: ' + Math.round(done/total*100) + '%');
            });
            xhr.addEventListener('load', function(e) {
                console.log('xhr upload complete', e, this.responseText);
            });
            xhr.open('post', 'http://webpage.com/images', true);
            var data = new FormData;
            data.append('file', file);
            xhr.send(data);
        });
    

    我在这里找到的: jQuery Upload Progress and AJAX file upload

    我得到403禁止的错误,并尝试了一切。。我正在使用opencart MVC ArchriteTure构建我的自定义仪表板。。 我的网站托管在goddady i) 我没有。此文件夹上的htaccess文件 ii)godaddy“hotlink protextion”的cpanel中有一个选项,我也在其中放置了URL!( http://webpage.com/images ) iii)尝试777作为文件夹权限

    但还是同样的错误。。我认为这是最适合我的解决方案的代码。。有什么建议吗?我做错了什么?

    1 回复  |  直到 7 年前
        1
  •  0
  •   Kiriakos Grhgoriadhs    7 年前

    我找到了解决方案。。。我实际上也更改了上述代码。。 首先,在我拥有的图像文件夹中,我创建了一个名为index的HTML文件。html 为了避免以下类型的错误,这一点非常重要: 没有匹配的DirectoryIndex(index.html.var、index.htm、index.html、index.xhtml….e.t.c.)。我是通过我的托管提供商(goddady)的错误日志文件发现这个错误的,下面这篇文章让我理解并给了我mre信息来找到它:

    https://www.liquidweb.com/kb/apache-error-no-matching-directoryindex-index-html-found-solved/

    文章说: “…意味着Apache将只查找名为index.html的目录索引文件”

    这解决了我的问题!

    我还更改了代码,以便使用openCart架构通过ajax上传图像,正如我在stackoverflow中提出的另一个问题中提到的那样。你可以在这里找到 upload image file through ajax and php ,以防有人在同一个问题上叠加