hey guys,

got a little issue i'm struggling with at the moment - got a page which displays an image based on a get variable from the url....

so for example the user is directed to www.mydomain.com/display.php?Image=myimage.jpg

What i need to do is have the page read this variable and display the image accordingly.

Tried something like this...

<?php
$imgsrc=$_GET["Image"]
?>
							<img border="1" src="library/<?php $src ?>" width="370" height="483">

but yeah... didnt work! lol
I know this is probably pretty simple, but i'm a php newbie to humour me 🙂
so yeah, any help appriciated!!

Cheers guys!!

Jonny

    Your problem is with this part:

    <?php $src ?>

    That PHP statement doesn't actually do anything. Perhaps you meant to [man]echo[/man] or [man]print[/man] the value of that variable instead? 😉

      ok, so i tried sticking the bit that gets the variable from the URL in the head tags of the .htm page and then using this...

      				[code=php]<?php 
      				"<img src=echo $imagepath>" 
      				?>[/code]

      but still got no luck!! 🙁
      it sucks because i cant debug myself as i'm not familiar with the syntax - i'm more of an actionscript kind guy... anyone know where i'm going wrong here?

        Still the same problem as last time. You've got a string, but that's it. You didn't tell PHP to actually do anything with that string (such as [man]echo[/man] or [man]print[/man] it).

        Also, you can't just throw PHP keywords/functions into the middle of a string and expect PHP to find it and parse it. See the manual page for what a [man]string[/man] is (especially the part about concatenating strings and/or variable interpolation inside of double quote delimited strings).

          the first issue is that you define a var$imgsrc containing the contents of your $GET var:

          <?php
          $imgsrc=$_GET["Image"]
          ?> 
          

          you have not defined any var named $src or $imagepath which you refer in your code examples.

          secondly, as brad g. pointed out, you need to [man]echo[man] or [man]print[/man] the contents of that var rather than just putting the var in a php block. something like this :

          echo '<img src="' . $imgsrc . '">';
          
            6 days later

            Still having no luck with this guys. 😕

            Here's what i'm using on the htm upload success page...

            <html>
            <head>
            <link rel="stylesheet" href="http://104.198.136.250/intranet
            <title>shibby - </title>
            <?php
            $imgsrc=$_GET["Image"]
            $imagepath="library/".$imgsrc
            ?>
            </head>
            <body background="btile.gif" topmargin="0" leftmargin="0" rightmargin="0" bottommargin="0" marginwidth="0" 
            
            marginheight="0">
            Your image was 
            uploaded successfully!</font></b></font></blockquote>
            <?php 
            echo '<img src="$imgpath">'; 
            ?>
            </body>
            </html>

            The page displays ok, just no image displayed from the php echo.
            the user is directed to this page with $image as a get variable in the URL, so http://mydomain.com?image=5.jpg

            Its probably something stupid i realise but i just cant put my finger on it 🙁

              that should ready echo '<img src="$imagepath">'; actually, but still doesnt work 🙁

                also tried dropping the second lot of php tags and just echoing instead, like this...

                echo "<img src='/library/".$imgsrc ."'><br>";

                which actually works to some extent... altho the link to the picture is broken.

                The browser tries to display an image but cant find the path... the path it is trying to load is:

                http://www.mydomain.co.uk/library/%22.$imgsrc%20.%22

                If i had hair, i'd be pulling it out now 🙁

                  Are you sure your file is being interpreted as PHP ? Note that if you've named your file something like my_script.html instead of my_script.php, then the web server won't bother to interpret any PHP code in the file.

                    Write a Reply...