bug #1258956, typo
[phpmyadmin/crack.git] / transformation_wrapper.php
blob1237b1719cd8d734f2dfead5796f15d7058a23e6
1 <?php
2 /* $Id$ */
3 // vim: expandtab sw=4 ts=4 sts=4:
5 $is_transformation_wrapper = true;
7 /**
8 * Get the variables sent or posted to this script and displays the header
9 */
10 require_once('./libraries/grab_globals.lib.php');
12 /**
13 * Gets a core script and starts output buffering work
15 require_once('./libraries/common.lib.php');
16 require_once('./libraries/relation.lib.php'); // foreign keys
17 require_once('./libraries/transformations.lib.php'); // Transformations
18 $cfgRelation = PMA_getRelationsParam();
20 /**
21 * Ensures db and table are valid, else moves to the "parent" script
23 require_once('./libraries/db_table_exists.lib.php');
26 /**
27 * Get the list of the fields of the current table
29 PMA_DBI_select_db($db);
30 $table_def = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table), NULL, PMA_DBI_QUERY_STORE);
31 if (isset($primary_key)) {
32 $result = PMA_DBI_query('SELECT * FROM ' . PMA_backquote($table) . ' WHERE ' . $primary_key . ';', NULL, PMA_DBI_QUERY_STORE);
33 $row = PMA_DBI_fetch_assoc($result);
34 } else {
35 $result = PMA_DBI_query('SELECT * FROM ' . PMA_backquote($table) . ' LIMIT 1;', NULL, PMA_DBI_QUERY_STORE);
36 $row = PMA_DBI_fetch_assoc($result);
39 // No row returned
40 if (!$row) {
41 exit;
42 } // end if (no record returned)
44 $default_ct = 'application/octet-stream';
46 if ($cfgRelation['commwork'] && $cfgRelation['mimework']) {
47 $mime_map = PMA_getMime($db, $table);
48 $mime_options = PMA_transformation_getOptions((isset($mime_map[urldecode($transform_key)]['transformation_options']) ? $mime_map[urldecode($transform_key)]['transformation_options'] : ''));
50 foreach ($mime_options AS $key => $option) {
51 if (substr($option, 0, 10) == '; charset=') {
52 $mime_options['charset'] = $option;
57 // garvin: For re-usability, moved http-headers and stylesheets
58 // to a seperate file. It can now be included by header.inc.php,
59 // queryframe.php, querywindow.php.
61 require_once('./libraries/header_http.inc.php');
62 // [MIME]
63 if (isset($ct) && !empty($ct)) {
64 $content_type = 'Content-Type: ' . urldecode($ct);
65 } else {
66 $content_type = 'Content-Type: ' . (isset($mime_map[urldecode($transform_key)]['mimetype']) ? str_replace('_', '/', $mime_map[urldecode($transform_key)]['mimetype']) : $default_ct) . (isset($mime_options['charset']) ? $mime_options['charset'] : '');
69 if (isset($cn) && !empty($cn)) {
70 $content_type .= "\n" . 'Content-Disposition: attachment; filename=' . urldecode($cn);
73 header($content_type);
75 if (!isset($resize)) {
76 echo $row[urldecode($transform_key)];
77 } else {
78 // if image_*__inline.inc.php finds that we can resize,
79 // it sets $resize to jpeg or png
81 $srcImage = imagecreatefromstring($row[urldecode($transform_key)]);
82 $srcWidth = ImageSX( $srcImage );
83 $srcHeight = ImageSY( $srcImage );
85 // Check to see if the width > height or if width < height
86 // if so adjust accordingly to make sure the image
87 // stays smaller then the $newWidth and $newHeight
89 $ratioWidth = $srcWidth/$newWidth;
90 $ratioHeight = $srcHeight/$newHeight;
92 if ($ratioWidth < $ratioHeight){
93 $destWidth = $srcWidth/$ratioHeight;
94 $destHeight = $newHeight;
95 }else{
96 $destWidth = $newWidth;
97 $destHeight = $srcHeight/$ratioWidth;
100 if ($resize) {
101 $destImage = ImageCreateTrueColor( $destWidth, $destHeight);
104 // ImageCopyResized( $destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight );
105 // better quality but slower:
106 ImageCopyResampled( $destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight );
108 if ($resize == 'jpeg') {
109 ImageJPEG( $destImage,'',75 );
111 if ($resize == 'png') {
112 ImagePNG( $destImage);
114 ImageDestroy( $srcImage );
115 ImageDestroy( $destImage );
119 * Close MySql non-persistent connections
121 if (isset($GLOBALS['dbh']) && $GLOBALS['dbh']) {
122 @PMA_DBI_close($GLOBALS['dbh']);
124 if (isset($GLOBALS['userlink']) && $GLOBALS['userlink']) {
125 @PMA_DBI_close($GLOBALS['userlink']);