Loading php file from database returning html not up to date

I am trying to download files from my database, which data is stored as blob. However, my code keeps returning the html file instead of the actual file.

Worse, the output is given the name "handleDownload" which is the name of my php script download and not the actual filename!

How can I fix this? Thank you in advance!

This is the tutorial I am following: http://www.w3programmers.com/file-upload-and-download-with-php/

Boot codes

$Download = new Download();
$result = array(); //store results of output
try {
    //if id is set then get file from database
      $id = $_GET['id'];
      //pump id in to function getDBFiles to pull file with matching id
      //get array containing file details from function getDBFiles
      $getFiles = $Download->getMessages();
      $size = $getFiles['size'];
      $type = $getFiles['type'];
      $name = $getFiles['name'];
      $content = $getFiles['content'];
      header("Content-length: $size");
      header("Content-type: $type");
      header("Content-Disposition: attachment; filename=$name");
      echo $content; exit;
    //execute retrieval of files from database
    //pass results to output array 
    $output = $Download->getMessages();
} catch (Exception $e) {
    $result[] = $e->getMessage();



Database codes

 protected $messages = array();
 public function showDBFiles() {
     global $database;
     $sql = "SELECT resume_id, resume_title FROM ".self::$table_name;
     $result = $database->query($sql);
         $this->messages[] = "Database is empty";
           while(list($id, $name) = mysqli_fetch_array($result)){
                  $this->messages[] = array('id'=>$id, 'name'=>$name);


public function getDBFiles($id) {
    global $database;
    $sql = "SELECT resume_title, file_type, file_size,resume_data FROM  ".self::$table_name." WHERE resume_id = $id";
    $result = $database->query($sql);
    list($name, $type, $size, $content) = mysqli_fetch_array($result);
            $this->messages[] = array('name'=>$name, 'type'=>$type, 'size'=>$size, 'content'=>$content);        

public function getMessages()
  return $this->messages;



source to share

All Articles