By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,775 Members | 1,425 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,775 IT Pros & Developers. It's quick & easy.

Why is this code for uploading files not really uploading files

P: 2
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.     // Connect to the database
  3.     $dbLink = new mysqli('127.0.0.1', 'user', 'pwd', 'myTable');
  4.     if(mysqli_connect_errno()) {
  5.         die("MySQL connection failed: ". mysqli_connect_error());
  6.     }
  7.  
  8.     // Query for a list of all existing files
  9.     $sql = 'SELECT `id`, `name`, `mime`, `size`, `created` FROM `file`';
  10.     $result = $dbLink->query($sql);
  11.  
  12.     // Check if it was successfull
  13.     if($result) {
  14.         // Make sure there are some files in there
  15.         if($result->num_rows == 0) {
  16.             echo '<p>There are no files in the database</p>';
  17.         }
  18.         else {
  19.             // Print the top of a table
  20.             echo '<table width="100%">
  21.                     <tr>
  22.                         <td><b>Name</b></td>
  23.                         <td><b>Mime</b></td>
  24.                         <td><b>Size (bytes)</b></td>
  25.                         <td><b>Created</b></td>
  26.                         <td><b>&nbsp;</b></td>
  27.                     </tr>';
  28.  
  29.             // Print each file
  30.             while($row = $result->fetch_assoc()) {
  31.                 echo "
  32.                     <tr>
  33.                         <td>{$row['name']}</td>
  34.                         <td>{$row['mime']}</td>
  35.                         <td>{$row['size']}</td>
  36.                         <td>{$row['created']}</td>
  37.                         <td><a href='get_file.php?id={$row['id']}'>Download</a></td>
  38.                     </tr>";
  39.             }
  40.  
  41.             // Close table
  42.             echo '</table>';
  43.         }
  44.  
  45.         // Free the result
  46.         $result->free();
  47.     }
  48.     else
  49.     {
  50.         echo 'Error! SQL query failed:';
  51.         echo "<pre>{$dbLink->error}</pre>";
  52.     }
  53.  
  54.     // Close the mysql connection
  55.     $dbLink->close();
  56.     ?>
Mar 22 '12 #1
Share this Question
Share on Google+
1 Reply


Dormilich
Expert Mod 5K+
P: 8,639
because this code is not supposed to upload files. check Atli's thread (PHP insights) for a full explanation of the code.
Mar 22 '12 #2

Post your reply

Sign in to post your reply or Sign up for a free account.