Image Links as Variable

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
D3Z
Forum Newbie
Posts: 4
Joined: Wed Aug 16, 2006 3:11 pm

Image Links as Variable

Post by D3Z »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Is it possible to use a http address as a variable?

I am entirely new to PHP and I am wanting to make it a bit easier to update information.

Code: Select all

<?php
$titledescription = 

"http://d3zign.co.uk/desert eagle.jpg";
?>

<html>
<head>
<style>
body {
  background-color: #fff;
  color: #000;
  font-family: "Verdana", serif;
  font-size: 11px;
  text-align: center;
}
.header {
  height: auto;
  width: 550px;
  background-color: #ffcc00;
  color: #000;
  font-weight: bold;
  text-transform: uppercase;
  font-style: italic;
  border: 1px solid #000;
  text-align: center;
  margin: 0px auto;
}

.section {
  height: auto;
  width: 546px;
  margin: 5px;
  border: 1px dashed #000;
  margin: 0px auto;
  border-top: 0px;
  text-align: left;
  padding: 2px;
}
  
</style>
</head>

<div class="header">XBOX 360 // GAMES // 

NBA LIVE '06</div>

<div class="section">FOr SAle <img 

src="<?php require("$titledescription"); 

?>"/></div>
I am just wondering why this doesn't work and if anybody can point me in the right direction.

Thanks in advance!


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Images cannot be sent in the same data stream as HTML. Require() will read and attempt to interpret the file given to it as PHP. Since an image clearly isn't a PHP file, you may want to use something else.

In this case, you don't need a function at all.

Code: Select all

<?php require("$titledescription");

?>
to

Code: Select all

<?php echo $titledescription; ?>
D3Z
Forum Newbie
Posts: 4
Joined: Wed Aug 16, 2006 3:11 pm

Post by D3Z »

have also tried that function and doesn't seem to be working either. Don't know whether it is because of the <img tag or not. Can php be put in an img tag?
D3Z
Forum Newbie
Posts: 4
Joined: Wed Aug 16, 2006 3:11 pm

Post by D3Z »

Obviously i am using firefox intially to test the page but when i go onto copy image location this is what comes up file:///f:/Web%20Stuff/Ebay%20Templates/%3C?php%20echo%20$titledescription;%20?%3E instead of the image location listed in the variable.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Is this file being processed by PHP? "echo" is one of the most basic and fundamental constructs of PHP. If it doesn't work, you've got something screwy.

If you view the source of the page this is in, do you see the PHP code? If so, the file isn't being processed by PHP.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

D3Z wrote:Obviously i am using firefox intially to test the page but when i go onto copy image location this is what comes up file:///f:/Web%20Stuff/Ebay%20Templates/%3C?php%20echo%20$titledescription;%20?%3E instead of the image location listed in the variable.
That would tell me that you aren't viewing the files through a web server. Have you installed Apache or IIS or some other web server?
D3Z
Forum Newbie
Posts: 4
Joined: Wed Aug 16, 2006 3:11 pm

Post by D3Z »

I am viewing the file through a web server becuase I have uploaded them to my website for testing as I do not have PHP installed on my system.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Can you post a link to it? The URL you got tells me otherwise, that's the issue I'm having with helping you more.
Post Reply