Jump to content

Recommended Posts

[quote author=Yesideez link=topic=245968.msg1149792#msg1149792 date=1238678182]
Just after [b]$found=type[/b] add this line:
[code=php:0]echo 'FOUND:'.$type;

 

ok,only from the stuff i know (not a lot) you put it after the end ({)

 

eg.

 

[code<?php session_start();

error_reporting(E_ALL | E_NOTICE);
error_reporting(E_ALL | E_STRICT);
error_reporting(E_ALL ^ E_NOTICE);

$picname = $_GET['picname'];

$arrFileTypes = array("gif", "jpg", "jpeg", "png");
foreach ($arrFileTypes as $type) {
  if ($fh=@fopen('images/'.$picname.'.'.$type,"r")) {
    $found=$type;
    fclose($fh);
  }
}
  echo 'FOUND:'.$type;
?>[/code]

 

and it prints FOUND:png

 

i use this url

 

http://jamesco.com/PhotoProcess.php?memberid=not

 

and its correct it is a PNG

 

 

P.S jamesco.com is a virtual domain for my localhost lol

check this out im really confused :S

 

ok i changed the code to this

 

<?php 

error_reporting(E_ALL | E_NOTICE); 
error_reporting(E_ALL | E_STRICT);
error_reporting(E_ALL ^ E_NOTICE);

$picname = $_GET['picname'];

$FileTypes = array("gif", "jpg", "jpeg", "png");

foreach ($FileTypes as $type) {

  if ($fh=@fopen('images/'.$picname.'.'.$type,"r")) {

    $found = $type;

    fclose($fh);
  }
}
   echo 'FOUND:    '. $type;
   echo '<br>';
   echo 'FOUND:    '. $picname;
   echo '<br>';
   echo 'FOUND:    '. $found;

?>

 

 

 

the url is this

 

http://jamesco.com/PhotoProcess.php?picname=apply

 

the real image is called * apply.gif *

 

look at what has been printed

 

FOUND: png

FOUND: apply

FOUND: gif

 

the $found var is working but i still dont know what to do to display :S

 

 

<?php 

error_reporting(E_ALL | E_NOTICE); 
error_reporting(E_ALL | E_STRICT);
error_reporting(E_ALL ^ E_NOTICE);

$picname = $_GET['picname'];

$root = "images/";

$FileTypes = array("gif", "jpg", "jpeg", "png");

foreach ($FileTypes as $type) {

  if ($fh=@fopen('images/'.$picname.'.'.$type,"r")) {

    $found = $type;

    fclose($fh);
  }
}
   echo 'FOUND:    '. $type;
   echo '<br>';
   echo 'FOUND:    '. $picname;
   echo '<br>';
   echo 'FOUND:    '. $found;
   echo '<br>';
   echo "<img src='$root$picname.$found'>";

?>

 

 

this prints

 

FOUND: png

FOUND: apply

FOUND: gif

 

 

THE IMAGE IS HERE!!

 

and is all working but i still dont know how to use externally :S

What exactly are you trying to do? Get an image to display when you goto your URL?

 

<?php 

$picname = $_GET['picname'];
$root = "images/";

$image = glob($root . $picname . ".*");

if (!is_array($image) || count($image) < 1) {
    $image[0] = "no-image.gif"; // make sure you have this file incase there is no image found.
}

$image = $image[0];
$type = end(explode(".", $image));
$size = filesize($image);

ob_start();
header('Last-Modified: '.date('r'));
header('Accept-Ranges: bytes');
header('Content-Length: '.$size);
header('Content-Type: image/' . $type);

readfile($image);
ob_end_flush();
?>

 

The code is untested, but that is what I gather you are after.

no i need it to display the image that is at the end of the * picname * in the url and auto find and add the prefix.

 

I doubt you understand what I just did, or eve tried it. Anyhow your answer is simple.

 

<?php 

$picname = $_GET['picname'];
$root = "images/";

$image = glob($root . $picname . ".*");

if (!is_array($image) || count($image) < 1) {
    $image[0] = "no-image.gif"; // make sure you have this file incase there is no image found.
}

header("Location: images/" . $image);
?>

 

Will redirect you, thus changing the url etc. That would be the only way to do what you have just described in the above. You cannot change the url without doing a redirect or formal submital. As far as will this work if you just include that URL in an image tag, I have no clue. I think it would, but yea. The only way to find out is for you to test it.

no i need it to display the image that is at the end of the * picname * in the url and auto find and add the prefix.

 

I doubt you understand what I just did, or eve tried it. Anyhow your answer is simple.

 

<?php 

$picname = $_GET['picname'];
$root = "images/";

$image = glob($root . $picname . ".*");

if (!is_array($image) || count($image) < 1) {
    $image[0] = "no-image.gif"; // make sure you have this file incase there is no image found.
}

header("Location: images/" . $image);
?>

 

Will redirect you, thus changing the url etc. That would be the only way to do what you have just described in the above. You cannot change the url without doing a redirect or formal submital. As far as will this work if you just include that URL in an image tag, I have no clue. I think it would, but yea. The only way to find out is for you to test it.

 

 

Hiya,

 

i tested the top code you posted and it worked!! thankyou so much mate !! seriusly your a life saver !! and thankyou so much to everyone else who tried !! :)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.