无法打印Ajax帖子中$ _FILES中收到的csv文件

时间:2018-08-16 13:20:53

标签: php

我的AJAX呼叫代码:

    var myform = document.getElementById("fileUploadForm");
    var formData = new FormData(myform);

    $.ajax({
             type: "POST",
             enctype: 'multipart/form-data',
             url: gSAHost+'/Csv/upload',
             data: formData,
             processData: false,
             contentType: false,
             cache: false,
             timeout: 600000,
             success: function (data) {           
                  console.log("SUCCESS : ", data);               
             },
             error: function (e) {             
                 console.log("ERROR : ", e); 

             }
         });

我的代码在Csv类文件的上传功能中

$row = 1;
if (($handle = fopen($_FILES['email_file']['tmp_name'], "r")) !== FALSE) {
      while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
              $num = count($data);
              echo "<p> $num fields in line $row: <br /></p>\n";
              $row++;
              for ($c=0; $c < $num; $c++) {
                   echo $data[$c] . "<br />\n";
              }
      }
      fclose($handle);
}
else{
    echo "<p>No CSV was found</p>";
}

正在执行$ _FILES ['email_file']的print_r。我在Csv类文件中得到以下输出:

SUCCESS :  Array
(
    [name] => two.csv
    [type] => text/csv
    [tmp_name] => /tmp/phpUf7IZq
    [error] => 0
    [size] => 101
)

我的代码正在进入else部分

echo "<p>No CSV was found</p>";

请指导,我在做什么

fopen($_FILES['email_file']['tmp_name'], "r")

0 个答案:

没有答案