Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

read dir after post

By: a guest on May 6th, 2013  |  syntax: PHP  |  size: 1.34 KB  |  views: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <html>
  2. <head>
  3. <title>Data Request</title>
  4. </head>
  5. <body>
  6. <h1 align="center">Dispatch Report</h1>
  7. <h2 align="center">Wrong Arrives Report</h2>
  8.  
  9. <table align="center" border="2">
  10. <tr>
  11. <td>Select Shift<br>
  12. <form method="post" action="" name="shiftfrm" id="shiftfrm">
  13. <select name="shiftlist" id="shiftlist">
  14.   <option value="" selected="selected">--------</option>
  15. <?php
  16. $dir = opendir ("files");
  17. while (false !== ($file = readdir($dir))) {
  18.         if($file!='.' && $file!='..') {
  19.                 echo '<option value="' . $file . '">' . $file . '</option>';
  20.         }
  21. }
  22. ?>
  23. </select>
  24. <input type="submit" id="submit" value="Submit"/>
  25. </form>
  26. </td></tr>
  27.  
  28. <?php
  29. if(!empty($_POST['shiftlist'])) {
  30.     $file = 'files/'.$_POST['shiftlist'];
  31.     echo $file;
  32.     if(file_exists($file)) {
  33.         if( ($handle = fopen( $file, 'r' )) !== false )
  34.         {
  35.             $output = '<table align="center" width="" border="2">';
  36.             while( ($data = fgetcsv( $handle )) !== false )
  37.             {
  38.                 $output .= '<tr>';
  39.                 foreach( $data as $value )
  40.                 {
  41.                     $output .= '<td>'.$value.'</td>';
  42.                 }
  43.                 $output .= '</tr>';
  44.             }
  45.             $output .= '</table>';
  46.             echo $output;
  47.             fclose( $handle );
  48.         }
  49.     }
  50. }
  51. ?>
  52.  
  53. </table>
  54.  
  55. </body>
  56. </html>