SERVER
' . htmlspecialchars(print_r($_SERVER, true)) . '
'; } # if ($_GET) { echo '
GET
' . htmlspecialchars(print_r($_GET, true)) . '
'; } # if ($_POST) { echo '
POST
' . htmlspecialchars(print_r($_POST, true)) . '
'; } # if ($_FILES) { echo '
FILES
' . htmlspecialchars(print_r($_FILES, true)) . '
'; } # if ($_REQUEST) { echo '
REQUEST
' . htmlspecialchars(print_r($_REQUEST, true)) . '
'; } # if ($_SESSION) { echo '
SESSION
' . htmlspecialchars(print_r($_SESSION, true)) . '
'; } # if ($_ENV) { echo '
ENV
' . htmlspecialchars(print_r($_ENV, true)) . '
'; } # if ($_COOKIES) { echo '
COOKIES
' . htmlspecialchars(print_r($_COOKIES, true)) . '
'; } $ruser = $_SERVER["REMOTE_USER"]; #if (!empty($ruser)) { echo "
Hello " . $ruser . ".

"; } /* ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== * * http://stackoverflow.com/questions/518795/dynamically-display-a-csv-file-as-an-html-table-on-a-web-page * * $Id: display.php,v 1.13 2014/11/21 17:28:13 pkern Exp $ */ $form = htmlspecialchars($_SERVER["PHP_SELF"]); $form = '

\n"; $mod = filemtime($my_paths["CSV"]); date_default_timezone_set("EST5EDT"); $stamp = strftime("%Y-%m-%d (%a) %H:%M %Z", $mod); $form .= "\n

\n"; $f = fopen($my_paths["CSV"], "r"); $before = array ('/\n *-/', '/\n/', '/#/'); $after = array ('

  • -', '
    ', '
    + '); $linenum = 0; $showrow = 0; if (($line = fgetcsv($f)) !== false) { $cn = 0; $linenum++; $h_row = "\n\n"; $form .= "\n"; foreach ($line as $cell) { $px = $cn % 3; if ($cn == 0) { $form .= "\n"; } elseif ($px == 0) { $form .= "\n\n"; } $form .= "\n"; $cn ++; if ($onlyRows) { $pattern = $matches[$cell]; $plen = strlen($pattern); $showrow += $plen; $findrow['len'][$cn] = $plen; $findrow['val'][$cn] = $pattern; } if ($onlyshow) { if ( $headers[$cell] != "checked" ) { $skipcol[$cn] = True; continue; } $skipcol[$cn] = False; } $pltext = htmlspecialchars($cell); $httext = preg_replace($before, $after, $pltext); $seg = "\n"; $h_row .= $seg; if ($savecsv) { $xcsv[$csvlines][$cn] = $cell; } } $h_row .= "\n\n"; $form .= "
    \n"; $form .= '   ' . "\n"; $form .= $cell . "\n"; $form .= ' ' . " \n"; $form .= "" . $httext . " ±

    \n"; $form .= ' '; $form .= ''; $form .= "   [ source CSV file was written:   " . $stamp . " ]  "; $form .= '

    '; $form .= "\n

  • \n"; # if no patterns to match then show all rows. if ($onlyRows and $showrow == 0) { $onlyRows = False; } } if ($savecsv) { $csvlines++; } elseif ($linenum > 0) { echo $form; echo '' . "\n"; echo $h_row; echo "\n"; } while (($line = fgetcsv($f)) !== false) { $cn = 0; $linenum++; $showrow = 0; $h_row = "\n"; foreach ($line as $cell) { $cn ++; if ($onlyRows and $findrow['len'][$cn] > 0 ) { $re = "/" . $findrow['val'][$cn] . "/"; if ( preg_match($re, $cell) == 1 ) { $showrow++ ; } } if ($onlyshow and $skipcol[$cn]) { continue; } $pltext = htmlspecialchars($cell); $httext = preg_replace($before, $after, $pltext); $seg = "\n"; $h_row .= $seg; if ($savecsv) { $xcsv[$csvlines][$cn] = $cell; } } $h_row .= "\n"; if ($onlyRows and $showrow == 0) { continue; } if ($savecsv) { $csvlines++; } else { echo $h_row; } } fclose($f); if ($savecsv) { ob_start(); date_default_timezone_set("EST5EDT"); $savefn = strftime("inventory-%Y%m%d-%H%M.csv"); header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename=' . $savefn); header('Content-Transfer-Encoding: binary'); $fpout = fopen("php://output", "w"); for ($i = 0 ; $i < $csvlines ; $i++ ) { $cs = "" ; $cline = ""; # fputcsv() will not enclose everything (sigh). foreach ($xcsv[$i] as $xcell) { ## XXX - what if xcell contains '"' ... ? $cline .= $cs . '"' . $xcell .'"' ; $cs = ","; } fwrite($fpout, $cline . "\n"); } fclose($fpout); ob_end_flush(); } elseif ($linenum > 1) { echo "\n
    " . $httext . "
    \n\n\n"; } ?>