<?php $endtime = time(); echo "Operation lasted " . time_diff_conv($starttime, $endtime) . "\n"; if (php_sapi_name() == "cli") { file_put_contents($out, csvDump($result_file)); } else { attachDownload($out, $result_file); }
function attachDownload($fname, $file) { header('Content-disposition: attachment; filename=' . $fname); header('Content-type: text/csv'); echo csvDump($file); }
<?php include 'osrmlib.php'; include 'input.php'; append("from;to;status;distance;time", $out); /* * Distance and time between all listed points */ for ($i = 0; $i < $size; $i++) { $rows = array(); for ($j = 0; $j < $size; $j++) { if ($i == $j) { continue; } $arrres = request($csv[$i]["node"], $csv[$i]["lat"], $csv[$i]["lon"], $csv[$j]["node"], $csv[$j]["lat"], $csv[$j]["lon"]); $rows[] = $arrres; } append(csvDump($rows), $out); } function append($message, $file = 'log.txt') { $handle = fopen($file, 'a'); if (!$handle) { echo "File cannot be opened"; } $message .= PHP_EOL; fwrite($handle, $message); fclose($handle); }