FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

Image Script not working.

 


Dougie1
My image script is not working. It should work because it works for jpgs but doesn't work for anything else. Is it because of the if statements? What should I do to sort it?
Code:
<?php
$image = $_GET['image'];


$filename = $image;
if (($pos = strrpos($filename, ".")) === FALSE){
  echo "No Dot In The File Name";}
else {
  $extension = substr($filename, $pos + 1);
  $extension = strtolower($extension);
}

    //jpeg
if ($extension == jpg || jpeg) {
header("Content-type: image/jpeg");
$im = imagecreatefromjpeg($image);
imagejpeg($im);
imagedestroy($im);}

    //png
if ($extension == png) {
header("Content-type: image/png");
$im = imagecreatefrompng($image);
imagepng($im);
imagedestroy($im);}

   //gif
if ($extension == gif) {
header("Content-type: image/gif");
$im = imagecreatefromgif($image);
imagegif($im);
imagedestroy($im);}

   //bmp
if ($extension == bmp) {
header("Content-type: image/bmp");
$im = imagecreatefrombmp($image);
imagebmp($im);
imagedestroy($im);}

   //tiff
if ($extension == tiff) {
header("Content-type: image/tiff");
$im = imagecreatefromtiff($image);
imagetiff($im);
imagedestroy($im);}
?>
MrBlueSky
1. Use quotes in your if statements
2. Use if ($extension == 'jpg' || $extension == 'jpeg') instead of if ($extension == 'jpg' || 'jpeg')

Code:

    //jpeg
if ($extension == 'jpg' || $extension == 'jpeg') {
header("Content-type: image/jpeg");
$im = imagecreatefromjpeg($image);
imagejpeg($im);
imagedestroy($im);}

    //png
if ($extension == 'png') {
header("Content-type: image/png");
$im = imagecreatefrompng($image);
imagepng($im);
imagedestroy($im);}

// etc.
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.