php中如何接收通过http传来的一个txt的文件
这个我没有头绪,刚接触PHP。像大家请教

解决方案 »

  1.   

    处理上传文件的教程
    http://www.php.net/manual/zh/features.file-upload.post-method.php
      

  2.   

    具体参考PHP手册:特点->文件上传处理
    http://download.csdn.net/detail/dmtnewtons/4122897
    #读取excel信息
    function readCSV($file) {
    $row = 1;
    $handle = fopen($file, "r");
    $arrTable = array ();
    while ($data = fgetcsv($handle, filesize($file), ",")) {
    $arrTab = array ();
    $num = count($data);
    $row++;
    for ($c = 0; $c < $num; $c++) {
    $arrTab[] = iconv("GBK", "UTF-8", $data[$c]);
    }
    array_push($arrTable, $arrTab);
    }
    fclose($handle);
    return $arrTable;
    }
    if(!empty($_FILES['datas'])){
    #Array ([name] => statusInfors.csv
    # [type] => application/vnd.ms-excel
    # [tmp_name] => C:\Windows\Temp\phpF49D.tmp
    # [error] => 0
    # [size] => 163 )
    $pathparts = pathinfo($_FILES['datas']['name']); if($pathparts['extension'] != "csv") turnInfor("请导入csv格式文件");
    $file = $_FILES['datas']['tmp_name'];
    $arrcsv = readCSV($file);
    print_r($arrcsv);
    }?>
         <form name="dataList" action="" method="post" enctype="multipart/form-data">
    <table  width="100%" border="0" cellpadding="0" cellspacing="0">
    <tr>
      <td colspan=2>
    <input type="button" name="import" value="导入数据" onclick="data.click()" />
    <input type="file" id="data" style="visibility:hidden;display:none;" name="datas" value="Import" onchange="importData()" />
    </td>
      </tr>
    </table>
    </form>
      

  3.   


    <script>
    function importData(){
            document.dataList.action = "infors_datas.php";
    document.dataList.submit();
    }
    </script>
      

  4.   

    谢谢,大家了,我前面思路不对,所以上网找得资料不对,导致没有做出来。
    现在我需要有个页面进行文件提交,并在后台处理,然后返回处理结果。
    感谢dream1206,看了文档后问题解决。