Blame view
view/downloadFile.php
1.65 KB
cf76164e6 20190709 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
<?php function prepend($string, $orig_filename) { $context = stream_context_create(); $orig_file = fopen($orig_filename, 'r', 1, $context); $temp_filename = tempnam(sys_get_temp_dir(), 'php_prepend_'); file_put_contents($temp_filename, $string); file_put_contents($temp_filename, $orig_file, FILE_APPEND); fclose($orig_file); return $temp_filename; } $file=$_GET['path']; //echo $file; $dir='/home/pi/Desktop/vAlert/rec/'; $fileArray=explode('/',$file); //print_r($fileArray); $filename=$fileArray[count($fileArray)-1]; if(substr($filename,0,4)=="DIN2") { $string[0]="DIN Report of ".substr($filename,3,4)."-".substr($filename,7,2)."-".substr($filename,9,2)." "; $string[1]="Hour:Minutes Seconds,Warning Level,Din Relay Register,Z-axis Peak,Z-axis: Frequency,Z-axis time in seconds,X-axis:Peak,X-axis:Frequency, X-axis time in seconds,Y-axis:Peak,Y-axis:Frequency,Y-axis time in seconds,Vector-axis Peak, Vector-axis:Frequency, Vector-axis time in seconds "; $tmp=file($file); $myfileArray=array_merge($string,$tmp); $mytempFile=$dir.'download.csv'; $fp=fopen($mytempFile,'w') or die("Cannot write file "); foreach ($myfileArray as $key => $value) { fwrite($fp,$value); } header("Content-type:application/pdf"); header('Content-Disposition: attachment; filename=' . $filename); readfile( $mytempFile); unlink($mytempFile); } else{ //echo $filename; header("Content-type:application/pdf"); header('Content-Disposition: attachment; filename=' . $filename); readfile( $file); //unlink($tmp); //echo '<script> window.history.back();</script>'; } ?> |