Jump to content

if image isn't present.


czukoman20

Recommended Posts

I have a piece of coding right now that calls for a users certain banner image. The problem is. Many users want to use different banners. So i have the code in my pagination page which searches for different banners and then displays them by the search. Well the only issue is that it only supports one file type... .jpeg.

   echo "<a href=\"http://www.adworld-online.com/submit.php?user=$username\"><img src=\"http://www.adworld-online.com/images/banners/". $username ."_banner.jpg\" width=\"600\" height=\"110\"><br />";

 

that is the banner code. How would i be able to make that say.. heyy if that banner is not there maybe i should check a different file format.

???

I would really appreciate some help please

Link to comment
Share on other sites

Thats hardly php scripting..

echo "<a href=\"http://www.adworld-online.com/submit.php?user=$username\"><img src=\"http://www.adworld-online.com/images/banners/". $username ."_banner.jpg\" width=\"600\" height=\"110\"><br />";

 

 

some effort would be nice

 

try something like

<?php
$types = array("jpg","gif","png");
$dir = "path/to/image/";
foreach($types as $type)
{
if(file_exists($dir.$username ."_banner.".$type))
{
echo "<a href=\"http://www.adworld-online.com/submit.php?user=$username\"><img src=\"http://www.adworld-online.com/images/banners/". $username ."_banner.".$type.\" width=\"600\" height=\"110\"><br />";
}
}
?>

 

Ok thats written on the fly.. just a basic idea

Link to comment
Share on other sites

<?phpif($session->logged_in){
$sub = "submit.php";
}
else{
$sub = "submit2.php";
}

$types = array("jpg","gif","png","swf");
$dir = "http://www.adworld/online.com/images/banners/";
foreach($types as $type)
{
if(file_exists($dir.$username ."_banner.".$type))
{
echo "<a href=\"http://www.adworld-online.com/$sub?user=$username\"><imgsrc=\"http://www.adworld-online.com/images/banners/". $username ."_banner.".$type." width=\"600\" height=\"110\"><br />";
}
}
?>

Im getting a parse error on the last line of the code which is embedded in a template and this is all i changed soo i'm not sure where the issue is.

Link to comment
Share on other sites

try this

 

<?php
if($session->logged_in)
{
$sub = "submit.php";
}else{
$sub = "submit2.php";
}

$types = array("jpg","gif","png","swf");
$dir = "http://www.adworld/online.com/images/banners/";
foreach($types as $type)
{
if(file_exists($dir.$username ."_banner.".$type))
{
	echo "<a href=\"http://www.adworld-online.com/$sub?user=$username\"><img src=\"http://www.adworld-online.com/images/banners/". $username ."_banner.".$type."\" width=\"600\" height=\"110\"><br />";


}
}
?>

Link to comment
Share on other sites

just spotted

 

$dir = "http://www.adworld/online.com/images/banners/";

 

you may have already spotted it and changed it, but might explain why banners arent being displayed?

 

try

$dir = "http://www.adworld-online.com/images/banners/";

Link to comment
Share on other sites

well yes i spotted that. but thanks. I changed it and... still nothing.

The error is happening at the

if(file_exists($dir.$username ."_banner.".$type))

thats not seeing the file for some wierd reason. the directory of the file is.

http://www.adworld-online.com/images/banners/mmallon_banner.jpg

and well for some reason, its not showing that it even exists. Hmm

any other ideas?

Link to comment
Share on other sites

ok well i think i may have found an issue with all of this in the first play. THE $types function is just displayed as Array

 

I have added an else echo

<?php 
if($session->logged_in)
{
$sub = "submit.php";
}else{
$sub = "submit2.php";
}

$types = array("jpg","gif","png","swf");
$dir = "http://www.adworld-online.com/images/banners/";
foreach($types as $type)
{
if(file_exists($dir.$username ."_banner.".$type))
{
	echo "<a href=\"http://www.adworld-online.com/$sub?user=$username\"><img src=\"http://www.adworld-online.com/images/banners/". $username ."_banner.".$type."\" width=\"600\" height=\"110\"><br />";


}else{
echo "$types";
echo "<br>";
echo "$dir";
echo "<br>";
echo "$username";
echo "<br>";
echo "$type";
}
}
}
?>

else{
echo "$types";
echo "<br>";
echo "$dir";
echo "<br>";
echo "$username";
           echo "<br>";
echo "$type";
}

 

thats the else statement.. here is what i says

types returns as a value of "array"

dir returns the right directory.

and type returns as "jpgarray".

i think this might be the issue.. but how do i resolve this.. Please help me out guys. any trys will be helpful

username returns the right username.. .so the issue is the actual $types code.

Link to comment
Share on other sites

<?phpif($session->logged_in)
{
$sub = "submit.php";
}else{
$sub = "submit2.php";
}

$types = array("jpg","gif","png","swf");
$dir = dirname(__FILE__)."images/banners/";
foreach($types as $type)
{
if(file_exists($dir.$username."_banner.".$type))
{
	echo "<a href=\"http://www.adworld-online.com/$sub?user=$username\"><img src=\"http://www.adworld-online.com/images/banners/".$username."_banner.".$type."\" width=\"600\" height=\"110\"><br />";
}
}
?>

 

well i forgot to say that i also tried this.. It still doesn't show up. the if file_exists isn't being triggered. soo idk what else... Thank you for your help so far.

More help is appreciated please.

 

this file is located at www.adworld-online.com/browse/sto.php

the picture is located in two places

www.adworld-online.com/browse/images/banners/mmallon_banner.jpg

www.adworld-online.com/images/banners/mmallon_banner.jpg

Link to comment
Share on other sites

okay

/ = root

/images/banners/madtechie_banner.jpg

/image.php

your use this

$dir = dirname(__FILE__)."/images/banners/";

 

/ = root

/images/banners/madtechie_banner.jpg

/class/image.php

your use this

$dir = dirname(__FILE__)."/../images/banners/";

 

try printing the $dir and check its pointing to the correct place

 

ahh i just typed this...

 

 

Ok the solved button has been removed :(

 

but i'll take your last post as a solved

Link to comment
Share on other sites

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.