hivtop Posted July 17, 2008 Share Posted July 17, 2008 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 More sharing options...
trq Posted July 17, 2008 Share Posted July 17, 2008 The new page url you have shown (http://www.mydomaine.com/insect/file=show.php?mantis2161.jpg) doesn't look like it was genrated by that code. can we see the relevent code or url? And please, use tags when posting code. Link to comment https://forums.phpfreaks.com/topic/115169-display-an-image-from-a-veriable/#findComment-592211 Share on other sites More sharing options...
hivtop Posted July 17, 2008 Author Share Posted July 17, 2008 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... Link to comment https://forums.phpfreaks.com/topic/115169-display-an-image-from-a-veriable/#findComment-592262 Share on other sites More sharing options...
mmarif4u Posted July 17, 2008 Share Posted July 17, 2008 try to give the absolute path. For exmaple: www.domain.com/images/ Now: <?php echo '<img src="www.domain.com/images/$file">'; ?> Link to comment https://forums.phpfreaks.com/topic/115169-display-an-image-from-a-veriable/#findComment-592264 Share on other sites More sharing options...
hivtop Posted July 17, 2008 Author Share Posted July 17, 2008 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 Link to comment https://forums.phpfreaks.com/topic/115169-display-an-image-from-a-veriable/#findComment-592277 Share on other sites More sharing options...
mmarif4u Posted July 17, 2008 Share Posted July 17, 2008 Are you sure the file name coming to that page is a valid pic name. Link to comment https://forums.phpfreaks.com/topic/115169-display-an-image-from-a-veriable/#findComment-592284 Share on other sites More sharing options...
hivtop Posted July 17, 2008 Author Share Posted July 17, 2008 Yes, I am sure.. if I cut the show.php?file= portion from the link in the address bar the image will load with no page formating (blank page - just the image) and thanks for your suggestions and questions... I am learning.. hahaha Link to comment https://forums.phpfreaks.com/topic/115169-display-an-image-from-a-veriable/#findComment-592303 Share on other sites More sharing options...
DoddsAntS Posted July 17, 2008 Share Posted July 17, 2008 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 Link to comment https://forums.phpfreaks.com/topic/115169-display-an-image-from-a-veriable/#findComment-592320 Share on other sites More sharing options...
hivtop Posted July 17, 2008 Author Share Posted July 17, 2008 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.... Link to comment https://forums.phpfreaks.com/topic/115169-display-an-image-from-a-veriable/#findComment-592335 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.