As Stephen said it looks like the array is not what you are expecting it to be, there are a few things you can do.
Try using
var_dump($pieces)
and take a look at what the array actually contains.
Another thing you can do to prevent errors and be more defensive in your code is something like the following:
$file = fopen($txtFile, "r");
while(!feof($file)) {
$line = fgets($file);
$pieces = explode(",", $line);
if(isset($pieces[0]))
$date = $pieces[0];
if(isset($pieces[1]))
$open = $pieces[1];
if(isset($pieces[2]))
$high = $pieces[2];
if(isset($pieces[3]))
$low = $pieces[3];
if(isset($pieces[4]))
$close = $pieces[4];
if(isset($pieces[5]))
$volume = $pieces[5];
}
}
Alternatively in this case you can just check the length of the $pieces, which for your use may be better and shorter, like this:
$file = fopen($txtFile, "r");
while(!feof($file)) {
$line = fgets($file);
$pieces = explode(",", $line);
if(sizeof($pieces) != 6){
//handle this case here
}
else
{
$date = $pieces[0];
$open = $pieces[1];
$high = $pieces[2];
$low = $pieces[3];
$close = $pieces[4];
$volume = $pieces[5];
}
}
This just ensures that the variables exist before try to do anything with them and will avoid the issue of undefined index.