php - Show selected text file in html page after submit button press -


good day ok, have done as understand , need direction , help. i'm new html/php please bear me. plan list text files dir in dropdown list, have done, display text file in same page in table upon submit button press. have far, input welcome still learning! bash script grep function grab specific lines original file , copy /tmp. again

<html> <head> <title>data request</title> </head> <body> <h1 align="center">dispatch report</h1> <h2 align="center">wrong arrives report</h2>  <table align="center" border="2"> <tr> <td>select shift<br> <form name="shiftfrm" id="shiftfrm"> <select name="shiftlist" id="shiftlist">   <option value="" selected="selected">--------</option> <?php $dir = opendir ("/var/www/files/");     while (false !== ($file = readdir($dir))) {             if (strpos($file, '.txt',1)) {                 echo '<option value="' . $file . '">' . $file . '</option>';             }     } ?> </select> <input type="submit" id="submit" value="submit"/>  <?php if( ($handle = fopen( '/tmp/sh130418n.txt', 'r' )) !== false ) { $output = '<table align="center" width="" border="2">'; while( ($data = fgetcsv( $handle )) !== false ) {     $output .= '<tr>';     foreach( $data $value )     {         $output .= sprintf( '<td>%s</td>', $value );     } fclose( $handle ); $output .= '</table>'; } echo $output; ?>  </td></tr> </table>  <?php $output = exec('/var/www/cgi-bin/manualexceptget.sh'); echo "<pre>$output</pre>"; ?>  </body> </html> 

assume <form method="post" action="">. augment file reading code:

if(!empty($_post['shiftlist'])) {     $file = 'files/'.$_post['shiftlist'];     if(file_exists($file)) {         if( ($handle = fopen( $file, 'r' )) !== false )         {             $output = '<table align="center" width="" border="2">';             while( ($data = fgetcsv( $handle )) !== false )             {                 $output .= '<tr>';                 foreach( $data $value )                 {                     $output .= '<td>'.$value.'</td>';                 }                 $output .= '</table>';             }             echo $output;             fclose( $handle );         }     } } 

edit: fixed isset() issue stated below. changed code, $handle closed before reading finished.

edit2: put in editor , saw many html tags, not placed (e.g. form not closed). working sample @ pastebin (tested on xampp)


Comments