0
<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?

Sambhu M R
  • 297
  • 5
  • 23

1 Answers1

0

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

Jakub Matczak
  • 15,341
  • 5
  • 46
  • 64