FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free 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.
Related topics
[java scripts ] Multimedia
the best site for script
Any good gallery scripts PHP
Help With Oakmailer
Jamatus' Dynamic image store
HTML submit textbox functions etc.
Need Rollover Image help
How to get a php script working under a cron job?
Need a captcha (anti-spam) added to my directory - 400FRIH$
Copy file script
Random image script
Linked image not working in javascript.
IE6 don't pass value on submiting an image type input tag. W
I want to output an img url from a random image script
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

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