title: php upload/download move uploaded file
body: <p>Having some issues with my upload/download process. My file is inserted to mysql as BLOB, but when downloaded it grabs the html markup of the calling php page.  Do I need to move uploaded file to a temporary directory before inserting to the database? </p>
  
  <p>EDIT: current upload.php file.  Still getting html content and not the actual file itself, it is still named correctly.</p>
  
  <pre><code>           &lt;?php
                      // Make sure an ID was passed DOWNLOAD HANDLER *******
  if(isset($_GET['id'])) {
  // Get the ID
      $id = intval($_GET['id']); var_dump($id);
  
  
      require_once ('../mysqli_connect.php'); //Connect to the db
  
  
  
          // Fetch the file information
          $downloadq = "
              SELECT `file_type`, `size`, `title`, 'content', 'upload_id'
              FROM `upload`
              WHERE `upload_id` =".$id;
          $result = mysqli_query ($dbc, $downloadq); // Run the query
  
  
          if($result) {
              // Make sure the result is valid
              if (mysqli_num_rows($result) &gt; 0) {
              // Get the row
                  $row = mysqli_fetch_assoc($result);
                  //var_dump($row);
  
                  // Print headers
                  header("Content-Type: application/msword");
                  header("Content-Length: ". $row['size']);
                 header("Content-Disposition: attachment; filename=". $row['title']);
                 header("Content-Transfer-Encoding: binary");
  
  
                  // Print data
                  echo (stripslashes($row['content']));
  
  
              }
              else {
                  echo 'Error! No such ID.';
              }
  
              // Free the mysqli resources
              mysqli_free_result($result);
          }
          else {
              echo "Error! Query failed: &lt;pre&gt;{$dbc-&gt;error}&lt;/pre&gt;";
          }
          mysqli_close($dbc);
  }
                  ?&gt;
  </code></pre>