Jump to content

display an image from a veriable


hivtop

Recommended Posts

Here goes...

I am trying to get a webpage on a fordor box to list all images in a dir ( this part works and displays as I want it to be) Then to display a picked image WITHIN a new page. (this part not working)

 

Here is the index page code:

 

<?php

?>

<HTML><HEAD><TITLE> bla bla bla

<BODY vLink=#800080 link=#0000ff bgcolor=#FF69B4>

<TABLE WIDTH=100% BORDER=2>

<TR><TD VALIGN=TOP ALIGN=RIGHT>

<center>On the Left is a pix of the insect.

<BR>On the Right is all the images I have of it.

</td>

</TR>

</TABLE>

<TABLE WIDTH=100% BORDER=2>

<TR><TD VALIGN=TOP ALIGN=RIGHT>

<img src="mantis.jpg" Title="the hunter">

</td>

<?

  include ('right.php');

?>

 

 

<?

  include ('footer.html');

?>

 

 

Code for right.php

 

<TD>

<center>

 

<?php

$dir = opendir (".");

        while (false !== ($file = readdir($dir))) {

                if (strpos($file, '.gif',1)||strpos($file, '.jpg',1) ) {

              print("<a href=\"show.php?".$file."\" target=\"new\">".$file."</a><br />\n");

                }

        }

?>

 

</td>

</TR>

</TABLE>

 

the above part works fine!!! it shows a pix of the insect (ON LEFT) and a list of all the image files in the dir on the right and gives the following for each file (jpg name different for each file), from view source:

 

<a href="show.php?file=mantis2161.jpg" target="new">mantis2161.jpg</a><br />

 

When I click on a link, a new page opens, the address bar reads:

 

http://www.mydomaine.com/insect/file=show.php?mantis2161.jpg

 

The page header, the file name and footer loads but a blank space holder for the image is displayed.

here is the code for show.php

 

<?php

?>

<HTML><HEAD><TITLE> bla bla bla</HEAD>

<BODY vLink=#800080 link=#0000ff bgcolor=#FF69B4>

 

<?

$file = $_GET['file'];

 

echo $file;

 

?>

<BR>

<?

print '<img src="/$file">';

 

?>

 

 

<?

  include ('footer.html');

?>

 

 

can anyone tell me what I missed to get the image to display on the page???

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/115169-display-an-image-from-a-veriable/
Share on other sites

Kind of new at this, so...

 

sorry about not using the


tags, will remember it in the future...

and sorry about the address bar link being copied wrong. should have been:

http://www.mydomaine.com/insect/show.php?file=mantis2161.jpg

it is the following piece of code that I can not get to display the image in the webpage.

<?
print '<img src="/$file">';

?> 

 

and thank you for your help...

changed print to echo and

tried to give the absolute path.

For exmaple:

 

www.domain.com/images/

and

http://www.domain.com/images/

and

public_html/images/

 

 

<?php
echo '<img src="www.domain.com/images/$file">';

?> 

<?php
echo '<img src="http://www.domain.com/images/$file">';

?> 

<?php
echo '<img src="public_html/images/$file">';

?> 

 

still no picture on the page (placeholder - yes, image - no)

I get the name of the file printed above the placeholder like the code should but no pix...

 

ps.. did changes one at a time... hahaha

Hi,

 

in the echo statments your using single quotes, this wont do the variable substitution you want so use the following instead

 

<?php
echo "<img src='http://www.domain.com/images/{$file}'>";
?>

or

<?php
echo "<img src=\"http://www.domain.com/images/{$file}\">";
?>

or

<?php
echo "<img src='http://www.domain.com/images/" . $file . "'>";
?>

 

 

A

THANK YOU!! THANK YOU!! THANK YOU!!

the first bit of code did it.....

 

if my second grade teacher could only see how I use quotes, commas and semicolons she would turn over in her grave (I'm 60 years old)

We all live and learn... hahaha

 

<?php
echo "<img src='http://www.domain.com/images/{$file}'>";
?>

 

mark this one SOLVED....

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.