tbl_get_field.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Provides download to a given field defined in parameters.
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. use PhpMyAdmin\Core;
  9. use PhpMyAdmin\Mime;
  10. use PhpMyAdmin\Response;
  11. /**
  12. * Common functions.
  13. */
  14. require_once 'libraries/common.inc.php';
  15. // we don't want the usual PhpMyAdmin\Response-generated HTML above the column's
  16. // data
  17. $response = Response::getInstance();
  18. $response->disable();
  19. /* Check parameters */
  20. PhpMyAdmin\Util::checkParameters(
  21. array('db', 'table')
  22. );
  23. /* Select database */
  24. if (!$GLOBALS['dbi']->selectDb($db)) {
  25. PhpMyAdmin\Util::mysqlDie(
  26. sprintf(__('\'%s\' database does not exist.'), htmlspecialchars($db)),
  27. '', false
  28. );
  29. }
  30. /* Check if table exists */
  31. if (!$GLOBALS['dbi']->getColumns($db, $table)) {
  32. PhpMyAdmin\Util::mysqlDie(__('Invalid table name'));
  33. }
  34. if (! isset($_GET['where_clause'])
  35. || ! isset($_GET['where_clause_sign'])
  36. || ! Core::checkSqlQuerySignature($_GET['where_clause'], $_GET['where_clause_sign'])
  37. ) {
  38. /* l10n: In case a SQL query did not pass a security check */
  39. Core::fatalError(__('There is an issue with your request.'));
  40. exit;
  41. }
  42. /* Grab data */
  43. $sql = 'SELECT ' . PhpMyAdmin\Util::backquote($_GET['transform_key'])
  44. . ' FROM ' . PhpMyAdmin\Util::backquote($table)
  45. . ' WHERE ' . $_GET['where_clause'] . ';';
  46. $result = $GLOBALS['dbi']->fetchValue($sql);
  47. /* Check return code */
  48. if ($result === false) {
  49. PhpMyAdmin\Util::mysqlDie(
  50. __('MySQL returned an empty result set (i.e. zero rows).'), $sql
  51. );
  52. }
  53. /* Avoid corrupting data */
  54. ini_set('url_rewriter.tags', '');
  55. Core::downloadHeader(
  56. $table . '-' . $_GET['transform_key'] . '.bin',
  57. Mime::detect($result),
  58. strlen($result)
  59. );
  60. echo $result;