source: www/work/phpmyadmin_1/transformation_wrapper.php@ 1

Last change on this file since 1 was 1, checked in by george, 17 years ago

Prvotní import všeho

File size: 4.2 KB
Line 
1<?php
2/* $Id: transformation_wrapper.php,v 2.3 2003/12/12 13:32:35 garvinhicking Exp $ */
3// vim: expandtab sw=4 ts=4 sts=4:
4
5$is_transformation_wrapper = true;
6
7/**
8 * Get the variables sent or posted to this script and displays the header
9 */
10require_once('./libraries/grab_globals.lib.php');
11
12/**
13 * Gets a core script and starts output buffering work
14 */
15require_once('./libraries/common.lib.php');
16require_once('./libraries/relation.lib.php'); // foreign keys
17require_once('./libraries/transformations.lib.php'); // Transformations
18$cfgRelation = PMA_getRelationsParam();
19
20/**
21 * Ensures db and table are valid, else moves to the "parent" script
22 */
23require_once('./libraries/db_table_exists.lib.php');
24
25
26/**
27 * Get the list of the fields of the current table
28 */
29PMA_mysql_select_db($db);
30$table_def = PMA_mysql_query('SHOW FIELDS FROM ' . PMA_backquote($table));
31if (isset($primary_key)) {
32 $local_query = 'SELECT * FROM ' . PMA_backquote($table) . ' WHERE ' . $primary_key;
33 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', '');
34 $row = PMA_mysql_fetch_array($result);
35} else {
36 $local_query = 'SELECT * FROM ' . PMA_backquote($table) . ' LIMIT 1';
37 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', '');
38 $row = PMA_mysql_fetch_array($result);
39}
40
41// No row returned
42if (!$row) {
43 exit;
44} // end if (no record returned)
45
46$default_ct = 'application/octet-stream';
47
48if ($cfgRelation['commwork'] && $cfgRelation['mimework']) {
49 $mime_map = PMA_getMime($db, $table);
50 $mime_options = PMA_transformation_getOptions((isset($mime_map[urldecode($transform_key)]['transformation_options']) ? $mime_map[urldecode($transform_key)]['transformation_options'] : ''));
51
52 foreach($mime_options AS $key => $option) {
53 if (substr($option, 0, 10) == '; charset=') {
54 $mime_options['charset'] = $option;
55 }
56 }
57}
58
59// garvin: For re-usability, moved http-headers and stylesheets
60// to a seperate file. It can now be included by header.inc.php,
61// queryframe.php, querywindow.php.
62
63require_once('./libraries/header_http.inc.php');
64// [MIME]
65if (isset($ct) && !empty($ct)) {
66 $content_type = 'Content-Type: ' . urldecode($ct);
67} else {
68 $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}
70
71if (isset($cn) && !empty($cn)) {
72 $content_type .= "\n" . 'Content-Disposition: attachment; filename=' . urldecode($cn);
73}
74
75header($content_type);
76
77if (!isset($resize)) {
78 echo $row[urldecode($transform_key)];
79} else {
80 // if image_*__inline.inc.php finds that we can resize,
81 // it sets $resize to jpeg or png
82
83 $srcImage = imagecreatefromstring($row[urldecode($transform_key)]);
84 $srcWidth = ImageSX( $srcImage );
85 $srcHeight = ImageSY( $srcImage );
86
87 // Check to see if the width > height or if width < height
88 // if so adjust accordingly to make sure the image
89 // stays smaller then the $newWidth and $newHeight
90
91 $ratioWidth = $srcWidth/$newWidth;
92 $ratioHeight = $srcHeight/$newHeight;
93
94 if( $ratioWidth < $ratioHeight){
95 $destWidth = $srcWidth/$ratioHeight;
96 $destHeight = $newHeight;
97 }else{
98 $destWidth = $newWidth;
99 $destHeight = $srcHeight/$ratioWidth;
100 }
101
102 if ($resize) {
103 $destImage = ImageCreateTrueColor( $destWidth, $destHeight);
104 }
105
106// ImageCopyResized( $destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight );
107// better quality but slower:
108 ImageCopyResampled( $destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight );
109
110 if ($resize == 'jpeg') {
111 ImageJPEG( $destImage,'',75 );
112 }
113 if ($resize == 'png') {
114 ImagePNG( $destImage);
115 }
116 ImageDestroy( $srcImage );
117 ImageDestroy( $destImage );
118}
119
120/**
121 * Close MySql non-persistent connections
122 */
123if (isset($GLOBALS['dbh']) && $GLOBALS['dbh']) {
124 @mysql_close($GLOBALS['dbh']);
125}
126if (isset($GLOBALS['userlink']) && $GLOBALS['userlink']) {
127 @mysql_close($GLOBALS['userlink']);
128}
129?>
Note: See TracBrowser for help on using the repository browser.