通过AJAX上传图像时禁止403

时间:2017-12-01 13:00:21

标签: opencart http-status-code-403 ajax-upload

我正在尝试找到问题的解决方案,而我正在尝试通过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

by @Rudie

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

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

1 个答案:

答案 0 :(得分:0)

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

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找到它,以防有人堆积同样的问题

相关问题