Advertisement
etandel

listallfiles.php

Dec 18th, 2014
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. <?php
  2.  
  3. // Database connection
  4. $dbconn = new mysqli('mysql17.000webhost.com', 'a2083177_mydb', 'password1', 'a2083177_mydb');
  5. if(mysqli_connect_errno())
  6. {
  7. die("MySQL connection failed: ". mysqli_connect_error());
  8. }
  9. $u_id = $_SESSION['user_id'];
  10. // query to display existing files
  11. $sql = "SELECT * FROM `files` where `u_id` ='$u_id'";
  12. $result = $dbconn->query($sql);
  13.  
  14. // check for success
  15. if($result)
  16. {
  17. // Files exist?
  18. if($result->num_rows == 0)
  19. {
  20. echo '<br><p>There are no files.</p>';
  21. }
  22. else
  23. {
  24. // table headings
  25. echo '<br>
  26. <table width="70%">
  27. <tr>
  28. <td><b>Name</b></td>
  29. <td><b>Type</b></td>
  30. <td><b>Size</b></td>
  31. <td><b>Received</b></td>
  32. <td><b>&nbsp;</b></td>
  33. <td><b>&nbsp;</b></td>
  34. </tr>';
  35.  
  36. // table data
  37.  
  38. while($row = $result->fetch_assoc())
  39. {
  40. echo "
  41. <tr>
  42. <td>{$row['name']}</td>
  43. <td>{$row['type']}</td>
  44. <td>{$row['size']}</td>
  45. <td>{$row['created']}</td>
  46. <td><a href='deletefile.php?u_id={$row['u_id']}'>Delete</a></td>
  47. <td><a href='downloadfile.php?u_id={$row['u_id']}'>Download</a></td>
  48.  
  49. </tr>";
  50. }
  51. echo '</table>';
  52.  
  53. }
  54. $result->free();
  55. }
  56. else
  57. {
  58. echo 'Error! query failed:';
  59. echo "<pre>{$dbconn->error}</pre>";
  60. }
  61. // Close the connection
  62. $dbconn->close();
  63. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement