[AppDB] appimage clean up

Paul van Schayck info at wwwdesign.tmfweb.nl
Fri Mar 19 07:57:37 CST 2004


Hey,

appimage.pgp was getting the content-type from the file extension. 
Now getting it from a builtin function.
Also added a imagedestroy(). Without it it would kill the server with too much visitors.
And switched the input variables to $_GET.

Changelog:
Get imagetype from getimagesize(). Switched to $_GET. Clearing memory.

Index: appimage.php
===================================================================
RCS file: /home/wine/appdb/appimage.php,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 appimage.php
--- appimage.php	15 Mar 2004 16:22:00 -0000	1.1.1.1
+++ appimage.php	19 Mar 2004 13:48:06 -0000
@@ -26,10 +26,11 @@
     exit;
 }

-if(!$appId && !$imageId) {
-    handle_error("No appId");
-    return;
-}
+$appId = $_GET['appid'];
+$imageId = $_GET['imageId'];
+$versionId = $_GET['versionId'];
+$width = $_GET['width'];
+$height = $_GET['height'];

 if(!$versionId) {
     $versionId = 0;
@@ -37,11 +38,14 @@

 opendb();

-if($imageId)
+if($imageId AND is_numeric($imageId) )
     $result = mysql_query("SELECT * FROM appData WHERE id = $imageId");
-else
+
+else if($appId AND $versionId AND is_numeric($appId) AND is_numeric($versionId) )
     $result = mysql_query("SELECT * FROM appData WHERE appId = $appId AND ".
-			  "versionId = $versionId AND type = 'image' LIMIT 1");
+			              "versionId = $versionId AND type = 'image' LIMIT 1");
+else
+	handle_error("IDs wrong");

 if(mysql_num_rows($result) == 0)
     handle_error("No image found");
@@ -55,42 +59,45 @@
 else
     $url = $ob->url;

-if(eregi(".+\\.(jpg|jpeg)$", $url))
-    $type = "jpeg";
-else
-if(eregi(".+\\.(png)$", $url))
-    $type = "png";
-
-if(!$type)
-    handle_error("Unknown Image Type");
+$imageInfo = getimagesize($url);

-if($type == "png")
-    $im = ImageCreateFromPNG($url);
+if( $imageInfo[2] == 2 )
+{
+	$type = 'jpeg';
+	$im = imagecreatefromjpeg($url);
+}
+else if( $imageInfo[2] == 3 )
+{
+	$type = 'png';
+	$im = imagecreatefrompng($url);
+}
 else
-if($type == "jpeg")
-    $im = ImageCreateFromJpeg($url);
+	handle_error("Unhandeled image type");

-if(!$im)
-    handle_error("Error");
+if( !$imageInfo || !$im)
+    handle_error("Error handeling file.");

-if($width && $height) {
+if($width && $height)
+{
     // do scaling
     $sim = ImageCreate($width, $height);
     ImageCopyResized($sim, $im, 0, 0, 0, 0, $width, $height, ImageSX($im), ImageSY($im));
-    $im = $sim;
 }

 // output the image
 if($type == "png")
 {
     header("Content-type: image/png");
-    ImagePNG($im);
+    ImagePNG($sim);
 }
 else
 if($type == "jpeg")
 {
     header("Content-type: image/jpeg");
-    ImageJPEG($im);
+    ImageJPEG($sim);
 }

+// Clear the memory
+imagedestroy($im);
+imagedestroy($sim);
 ?>




More information about the wine-patches mailing list