Forum Moderators: coopster

Message Too Old, No Replies

Challenging Image Display issue

i.e. "help!"

         

mcjohnson

6:52 pm on Jun 26, 2007 (gmt 0)

10+ Year Member



Here's my issue. I am using an out of the box program to manage the content of this site but using my own code to DISPLAY same.

I have an area where the user can upload an image. Let's say "dog.jpg". the image goes into the MySQL database row encoded like "18783676456776.jpg:dog.jpg" and then the actual IMAGE goes into a folder with just the encrypted name, i.e. 18783676456776.jpg

I am quite certain the CMS decrypts it when it displays it but as I said, I am writing my own output.

Hence when I try to display the image, here is the variable:

$Image = $row['Image'];

and here is the call:

echo "<img src='http://www.mysite.com/articlelive/page_images/$Image' border=1>";

When I call the row from the database it's trying to display 18783676456776.jpg:dog.jpg but of course the image itself is now simply 18783676456776.jpg

What I ewould like to do is STRIP everything from the colon on, so taht when PHP tries to display it, the name it is trying to display matches the name of the actual image in the folder.

Can this be done?

Thanks!

d40sithui

7:16 pm on Jun 26, 2007 (gmt 0)

10+ Year Member



U can try searching for the colon , then finding that character position in the string, then use the substr to read only the first portion of the string (up until the colon).

Or another method i can think of is to use the split function like something such as this.
<?
$pattern = ":";
//$new_image would contain stripped string for displ.
list($new_image, $junk) = split($pattern, $image);
?>

mcjohnson

11:50 am on Jun 27, 2007 (gmt 0)

10+ Year Member



Arrggghh! I am still flummoxed!

the Mysql db holds this info in a row called "Image":

290346193f2f388b9f43494e1ed5af2d.jpg:iprecon_hawkeye_360.jpg

I am using the "split" function in PHP to sepaate the gobblegook at the beginning from the jpg name at the end, as such:

list($a, $b) = split('[:]', $Image);

the actual IMAGE is sitting in a folder called "page_images" but it's named after the gobbldegook:

290346193f2f388b9f43494e1ed5af2d.jpg

Since I have defined the first half of the split as $a, I am trying to call and display the image as follows:

echo "<img src='http://www.example.com/articlelive/page_images/$a' border=1>";

But I am getting nothing.

HELP! This is very maddening and it's got me stopped in my tracks.

Best regards,

Pat

[edited by: jatar_k at 2:42 pm (utc) on June 27, 2007]
[edit reason] please use example.com [/edit]

Habtom

12:02 pm on Jun 27, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This might help:
$name = "290346193f2f388b9f43494e1ed5af2d.jpg:iprecon_hawkeye_360.jpg";
$exploded = explode(":", $name);
$a = $exploded['1'];
echo "<img src='http://www.example.com/articlelive/page_images/$a' border=1>";

You might need to remove that URL, URL are not allowed.

Habtom

mcjohnson

6:29 pm on Jun 27, 2007 (gmt 0)

10+ Year Member



For the life of me I am still struggling. Here is the entire code:

<?PHP
$Title =$row['Title'];
$Content =$row['Content'];
$PageID = $row['PageID'];
$MetaDesc = $row['MetaDesc'];
$Image = $row['Image'];
list ($a, $b) = explode(":", $Image);

$query = "select * from ArticleLive_pages WHERE AuthorID = 3
order by PageID desc limit 1 ";

$results=mysql_query($query) or die (mysql_error());
while ($rows=mysql_fetch_array($results)) {
extract ($rows);
echo stripslashes("<font face=arial size=2>$Title");
echo "&nbsp;&nbsp;&nbsp;<a href='http://www.mysite.com/news2.php?PageID=$rows[PageID]'>";
echo "<font color=#800000>(more)</font>";
echo "</a>";
echo "<br>";
echo "<img src='http://www.mysite.com/articlelive/page_images/$a' border=0>";

}
?>

What's odd is that if I echo "$Image" the full array displays, so I know I am getting the data out of the db. But when I go to "explode" it, I can't seem to get the data to do anything. If I do a simple "echo $a" or "echo $b", nothing.

Is there something glaring that I am overlooking?>

THNKSSS!

mcjohnson

8:56 pm on Jun 27, 2007 (gmt 0)

10+ Year Member



Got it. I had my explode statement in the wrong place. Rock on. I love it when a plan comes together.