Merge remote branch 'origin/master'
[phpmyadmin-themes.git] / tbl_get_field.php
blobac123572ae52a8bcb28464413ad801a046c1c5af
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Provides download to a given field defined in parameters.
5 * @version $Id$
6 * @package phpMyAdmin
7 */
9 /**
10 * Common functions.
12 require_once './libraries/common.inc.php';
13 require_once './libraries/mime.lib.php';
15 /* Check parameters */
16 PMA_checkParameters(array('db', 'table', 'where_clause', 'transform_key'));
18 /* Select database */
19 if (!PMA_DBI_select_db($db)) {
20 PMA_mysqlDie(sprintf(__('\'%s\' database does not exist.'), htmlspecialchars($db)),
21 '', '');
24 /* Check if table exists */
25 if (!PMA_DBI_get_columns($db, $table)) {
26 PMA_mysqlDie(__('Invalid table name'));
29 /* Grab data */
30 $sql = 'SELECT ' . PMA_backquote($transform_key) . ' FROM ' . PMA_backquote($table) . ' WHERE ' . $where_clause . ';';
31 $result = PMA_DBI_fetch_value($sql);
33 /* Check return code */
34 if ($result === false) {
35 PMA_mysqlDie(__('MySQL returned an empty result set (i.e. zero rows).'), $sql);
38 /* Avoid corrupting data */
39 @ini_set('url_rewriter.tags', '');
41 header('Content-Type: ' . PMA_detectMIME($result));
42 header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT');
43 header('Content-Disposition: attachment; filename="' . $table . '-' . $transform_key . '.bin"');
44 if (PMA_USR_BROWSER_AGENT == 'IE') {
45 header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
46 header('Pragma: public');
47 } else {
48 header('Pragma: no-cache');
49 // test case: exporting a database into a .gz file with Safari
50 // would produce files not having the current time
51 // (added this header for Safari but should not harm other browsers)
52 header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
54 echo $result;