【问题标题】:Not allowed to load local resource [image upload]不允许加载本地资源【图片上传】
【发布时间】:2014-03-21 10:09:59
【问题描述】:

这是我的sn-p ajax 一个上传提交文件的服务器端脚本。它在input[type=file] 的change 上触发。

    $('#magLogo').on('change', function(e) {
        var $input = $(this);
        var file = e.currentTarget.files[0];
        var data = new FormData();

        data.append('file', file);

        $.ajax({
          type: "POST",
          data: data,
          cache: false,
          contentType: false,
          processData: false,
          url: 'my/path/to/upload/script.php'
        })
          .done(function(fullPath) {
            $input
                .parents('#magLogoCont')
                .css('background-image', "url('"+fullPath+"')");
          });
    });

另一方面,PHP 脚本返回一个 JSON 字符串,其中包含上传文件的临时目录(我在 Windows 上运行时看起来像 file:///C:/wamp/tmp/filename.jpg)。

问题是当我想将此图像作为 div 的背景以向用户显示它已上传时,我在控制台中收到的错误为 Not allowed to load local resource)。我无法将它直接上传到最终目录中,因为在用户选择要上传的图像时,所有信息都不可用。

有没有办法做我想做的事?

非常感谢!

【问题讨论】:

    标签: php jquery ajax upload tmp


    【解决方案1】:

    不,您不能通过这样的“url”/路径将文件集成到浏览器。

    将图像移动到网页的 httpfiles 根目录下的文件夹,并以相对方式指向该路径。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-10-08
      • 2016-11-04
      • 1970-01-01
      • 2014-12-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多