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

<?php 
$Download = new Download();
$result = array(); //store results of output
try {
    //if id is set then get file from database
    if(isset($_GET['id'])){ 
      $id = $_GET['id'];
      //pump id in to function getDBFiles to pull file with matching id
      $Download->getDBFiles($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
    $Download->showDBFiles();
    //pass results to output array 
    $output = $Download->getMessages();
    //var_dump($output);
} 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);
     if(mysqli_num_rows($result)==0){
         $this->messages[] = "Database is empty";
     }else{
           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;
}

      

+3
oop database php mysql blob


source to share


No one has answered this question yet

Check out similar questions:

4270
Link. What does this symbol mean in PHP?
2335
Removing an element from an array in PHP
2024
How do you parse and process HTML / XML in PHP?
1906
How does PHP foreach work?
1475
Converting HTML + CSS to PDF with PHP?
1065
Link. What does this error mean in PHP?
1031
How can I list tables in a SQLite database file that was opened with ATTACH?
792
Returning JSON from PHP script
3
Zend / PHP: file upload / download issue to / from MySQL BLOB field
1
Loading php file with returning incorrect output



All Articles
Loading...
X
Show
Funny
Dev
Pics