/    Sign up×
Community /Pin to ProfileBookmark

photo will not display when thumbnail clikcked

When the thumnails are click only the first photo in the array shows. I have been unable to figure out where the problem is:
[url]http://plsnm.com/info.php?id=467&[/url] f=1239807849_offer_DSC02197.JPG

here is the code snippet
if(!empty($a1[image]))
{
//$MyImages = explode(“|”, $a1[image]);

$ShowInfo .= “<table valign=top align=center height=50><tr>”;

while(list(,$v) = each($im_array))
{

$ShowInfo .= “<td align=center valign=top width=”50″ height=50><a href=”info.php?id=$_GET[id]& f=$v”><img src=”re_images/$v” width=50 height=50 border=0></a></td>”;
}

$ShowInfo .= “</table><hr size=1 width=”95%” color=#336699><br>”;

if(!empty($f))
{
$ShowInfo .= “<center><img src=”re_images/$f” height=480 width=640></center><br>”;
}
else
{
$ShowInfo .= “<center><img src=”re_images/$im_array[0]” height=480 width=640></center><br>”;
}

}
else
{
$ShowInfo .= “<br><center><img src=”no_image.gif”></center>”;
}

any help is greatly appreciated
DD

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@SrWebDeveloperNov 25.2009 — Please always use the PHP tag when posting that kind of code here.

[B]Find:[/B]

[code=php]if(!empty($f))
{[/code]


[B]Change to:[/B]

[code=php]if (isset($_GET['f']) && !empty(trim($_GET['f'])) && file_exists("re_images/".trim($_GET['f'])))
{
$f="re_images/".trim($_GET['f']);[/code]


In your code you assume $f is populated with the "f" url argument value. This would only be true if register_globals is on, which was turned off since 4.2.0 and deprecated in 5.3.0 and will be removed in 6.0 in the future. So always reference url arguments via $_GET. As you can see I check to see if its set (the proper way), make sure it's not empty even if trimmed, then check to ensure the file exists with your path included. If so, I then set $f to the trimmed value with the path. The rest of your code takes over from there.

This procedure also helps protect against URL hacking attempts (injection oriented) as well.

The above code was written quickly and is untested - if any minor mistakes you can fix, but hope you follow what I'm doing here in general.

On a side note, might want to consider adding a Javascript method to do the same and avoid page refresh (keeping your PHP method intact for those who disable or don't support JS of course) i.e. put the large photo in a div, use JS to change the div's innerHTML based on the current thumbnail selected. Just sayin'.

-jim
Copy linkTweet thisAlerts:
@desertdirkauthorNov 25.2009 — thanks for the reply. I get this error with the code you suggested:

Fatal error: Can't use function return value in write context in /var/www/plsnm/info.php on line 217

Line 217 is the first line of your code.

DD
Copy linkTweet thisAlerts:
@SrWebDeveloperNov 25.2009 — I told you I wrote that quick. ?

Make that:

[code=php]if (isset($_GET['f']) && !empty($_GET['f']) && file_exists("re_images/".trim($_GET['f'])))
{
$f="re_images/".trim($_GET['f']); [/code]


But more importantly, get the concept here? ?

-jim
Copy linkTweet thisAlerts:
@desertdirkauthorNov 25.2009 — Yes I understand. Thanks for the help. That worked. This is one of those things where I stepped into the middle of something and was asked to fix it if possible.

I appreciate it

DD
×

Success!

Help @desertdirk spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...