上传CSV然后将结果存储到数组中

I've been working on this problem for a few hours and have used many resources from the web and stack overflow, but I can't seem to get past this last thing. I'm in the middle of attempting to get the contents of a csv file and store them in an array and print the results on another page via a session.

index.php (Shows form for uploading file)

<html>
<form action="http://mysite.org/~me/upload.php" method="POST" enctype="multipart/form-data">
<input type="file" name="file"><br />
<input type="submit" value="Now upload it!">
</form>
</html>

upload.php (if CSV, output filesize, print_r the array that should contain all data)

<?php
session_start();

if (($_FILES["file"]["type"] == "application/vnd.ms-excel"))
{
  if ($_FILES["file"]["error"] > 0)
    {
        echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
else
{
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";

    $file = fopen($_FILES["file"]["tmp_name"], 'r');
    while (($line = fgetcsv($file)) !== FALSE) {
    //$line is an array of the csv elements
    print_r($line);
    $_SESSION['line']=$line;

}
fclose($file);

   }
 }
else
 {
 echo "Invalid file";
 }
  echo "<a href='http://mysite.org/~me/yes.php'>Yes</a>";

 ?>

yes.php

<?php
session_start();
$data = $_SESSION['line'];
print_r($data);
?>

The print_r from the upload page should be the same as the print_r from the yes page, but it is not. It is only showing the last array. I don't understand how I would go about this problem.

As a side note: I've only been programming in php for about 2 weeks so please be thoughtful enough to explain your answers. It really helps! Thanks =)

You need to append instead of overwrite $_SESSION['line'].

Instead of:

$_SESSION['line'] = $line; // overwriting $_SESSION['line'] w/ each iteration

You need to:

$_SESSION['lines'][] = $line; // pushes the line to an array

Then on, yes.php, you can:

session_start();
$data = $_SESSION['lines'];
print_r($data);