Location: PHPKode > projects > Knowledge Box > knowledgebox/io/file.php
<?php

  /*
   * Free IT Foundation
   * Free Technology Serving Knowledge
   * http://www.free-it-foundation.org
   * 
   * This file is part of Knowledge Box.
   * 
   * Knowledge Box is free software: you can redistribute it and/or modify
   * it under the terms of the GNU General Public License as published by
   * the Free Software Foundation, either version 3 of the License, or
   * (at your option) any later version.
   * 
   * Knowledge Box is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU General Public License for more details.
   * 
   * You should have received a copy of the GNU General Public License
   * along with Knowledge Box.  If not, see <http://www.gnu.org/licenses/>.
   */


  // lib
  require_once ('../require/constants.php');

  // dotProject config
  require_once ('../../../includes/config.php');

  // bypass the dotProject framework
  $db = mysql_connect ($dPconfig ['dbhost'], $dPconfig ['dbuser'], $dPconfig ['dbpass'])
        or die ('Couldn\'t connect to database server');

  // select db
  $dblink = mysql_select_db ($dPconfig ['dbname'], $db)
            or die ('Couldn\'t connect to database ' . $dPconfig ['dbname']);

  // query
  $sql  = "SELECT * FROM " . KB_TABLE_SUBSTANCES;
  $sql .= " WHERE entry_id = " . (int) $_GET ['entry'];
  $sql .= " AND field_id = " . (int) $_GET ['field'];

  // record
  $record = mysql_query ($sql)
            or die ('Couldn\'t get record!');

  // empty record
  if (mysql_num_rows ($record) == 0)
  {
    print ('Couldn\'t get record!');
    exit ();
  }

  // get values
  $fileName = @mysql_result ($record, 0, 'textvalue');
  $bytes = @mysql_result ($record, 0, 'binaryvalue');
  $mimeType = @mysql_result ($record, 0, 'mime');

  // header
  header ('Content-type: ' . $mimeType);
  header ('Content-Disposition: attachment; filename="' . $fileName . '"');

  // stream
  print ($bytes);

  // exit
  exit ();

?>
Return current item: Knowledge Box