dongya2030 2016-08-25 06:59
浏览 43

Excel文件上传错误

<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="excelfile">
<input type="submit" name="upd" value="Upload">
</form>

I want to upload sample.xls

this is my upload script.

<?php
if(isset($_POST["upd"]))
{
$file = $_FILES['excelfile']['tmp_name'];
        $handle = fopen($file, "r");
        $c = 1;
        $heading = true;
        while(($filesop = fgetcsv($handle, 1000, ",")) !== false)
        {
            if($heading) {
        $heading = false;
        continue;
            }
            echo "<tr><th>".$c."</th><th>".$filesop[0]."</th></tr>";
            $c = $c + 1;
        }
}
?>

Here is the output screenshot http://screencast.com/t/RqZWnz1y
CSV files works correctly.. How to solve this problem?

  • 写回答

1条回答 默认 最新

  • douzhanlie9209 2016-08-25 07:01
    关注

    CSV file is a simple text file. You can open it in a notepad and read the content.

    XLS on the other hand is a binary file which means it doesn't simply contains text. Therefore you can't handle .xls files just like .txt file.

    In order to handle Excel's files you can try with some ready library like PHPExcel

    评论

报告相同问题?

悬赏问题

  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图