【问题标题】:Upload files via jquery $.post通过 jquery $.post 上传文件
【发布时间】:2013-11-29 20:13:29
【问题描述】:

对于发送 ajax 表单,我使用以下代码:

<input type="file" class="file_1" id="file" />
  • 注意:不要使用“FORM”标签

我的 jQuery 代码:

var file = $('#file').val();
$.post('form.php', {file:file}, function(data){});

还有我的 PHP 代码:

if($_FILES["file"]["tmp_name"] != '') {
            $fileName = $_FILES["file"]["name"];
            $fileTmpLoc = $_FILES["file"]["tmp_name"];
            $fileType = $_FILES["file"]["type"];
            $fileSize = $_FILES["file"]["size"];
        }
echo $fileName;

但是这段代码不起作用

【问题讨论】:

标签: php jquery ajax upload


【解决方案1】:

您正在尝试发布地址名称(换句话说,您发布了一个字符串),但文件上传需要是一个文件。 那么你可以从这个链接中找到答案:

Uploading both data and files in one form using Ajax?

【讨论】:

    【解决方案2】:

    我认为你不能。 尽管如此,还是有一些工具可以“模仿”它。 检查本教程: http://hayageek.com/ajax-file-upload-jquery/

    或者这个问题: Is it possible to use Ajax to do file upload?

    【讨论】:

      猜你喜欢
      • 2015-12-06
      • 2011-07-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-13
      • 1970-01-01
      相关资源
      最近更新 更多