我是 PHP 新手,我遇到了这个问题。
$mimes = array('application/vnd.ms-excel','text/plain','text/csv','text/tsv');
if (((in_array($_FILES['uploadedfile']['type'],$mimes)))
&& ($_FILES["uploadedfile"]["size"] > 0))
{
$filename = $_SESSION['username'].$_FILES["uploadedfile"]["name"];
move_uploaded_file($_FILES["uploadedfile"]["tmp_name"],"./uploads/".$filename);
echo "Stored in: " . "./uploads/" .$filename;
echo "<br />\n";
echo 'Daylight hours will be calculated for this latitude : '.$_POST['latCSV'];
echo "<br>";
//print out uploaded file.csv
echo "<table BORDER=1>\n\n";
echo " <tr><th>AvgCrown</th><th>MinCrown</th><th>MaxCrown</th><th>dateLogged</th><th>DaylightHours</th></tr>";
echo "<tbody id='tblBdyLoggedData'>";
$f = fopen("./uploads/" .$filename, "r");
$i=0; //just a counter
while (($line = fgetcsv($f)) !== false) {
echo "<tr>";
foreach ($line as $cell) {
// Save the value before you output
$lastColValue = htmlspecialchars($cell);
//unset($lastColValue[3]);
echo "<td>" . $lastColValue . "</td>";
}
//checking if date is valid
checkDateString($lastColValue);
// If you want to store all log dates in an array:
$logDates[] = $lastColValue;
$firstlogDate = $logDates[$i];
echo "<td>" . checkDateString($lastColValue) . "</td>";
//call function using firstlogDate for every row
echo "<td>" . calcDaylight($firstlogDate,$_POST["latCSV"]) . " </td>";
echo "</tr>\n";
$i = $i+1;
}
fclose($f);
echo "</tbody></table></body></html>";
}
我想在文件上传时只打印 CSV 文件的前 3 列,因为另外两列将使用各自的函数进行计算。Datelogged 将从 csv 中获取并正确重新格式化,并且还会根据 datelogged 计算日光时间。