1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

img and php

Discussion in 'PHP' started by jonhyhar, Jun 14, 2010.

  1. #1
    hey guys, how can i show images by php?

    i mean

    image;
    <img src="http://www.site.com/img/324.jpg" />
    Code (markup):
    i want to use it like;

    <img src="http://www.site.com/image.php?id=324" />
    Code (markup):

    what's the image.php?

    
    <?php
    $id = intval($_GET['id']);
    header('Content-Type: image/jpeg');
    
    // i couldn't do after this line
    
    "http://www.site.com/img/".$id.".jpg";    // ??
    
    ?>
    
    Code (markup):
     
    jonhyhar, Jun 14, 2010 IP
  2. s_ruben

    s_ruben Active Member

    Messages:
    735
    Likes Received:
    26
    Best Answers:
    1
    Trophy Points:
    78
    #2
    Try this:

    
    $id = intval($_GET['id']);
    $the_image_file = "/img/".$id.".jpg";
    $image = imagecreatefromjpeg($the_image_file);
    header('Content-type: image/jpeg');
    imagejpeg($image);
    imagedestroy($image);
    
    Code (markup):
     
    s_ruben, Jun 14, 2010 IP
    jonhyhar likes this.
  3. strgraphics

    strgraphics Active Member

    Messages:
    710
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #3
    No Need man its simple...!

    <?php
    echo "<img src='your image.jpg' width='300' height='500'>"
    ?>
     
    strgraphics, Jun 14, 2010 IP
  4. sijumpk

    sijumpk Peon

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Any html can be displayed in the browser by using echo or print. Like
    <?php
    $id = intval($_GET['id']);
    echo "<img src='http://www.site.com/img/".$id.".jpg'>"
    ?>

    or

    <?php
    $id = intval($_GET['id']);
    print "<img src='http://www.site.com/img/".$id.".jpg'>"
    ?>
     
    sijumpk, Jun 15, 2010 IP
  5. aeroz1

    aeroz1 Active Member

    Messages:
    492
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #5
    Though I am not sure but I think you're lacking a closing quotation mark and a semi-colon on this line:
     
    aeroz1, Jun 15, 2010 IP
  6. sijumpk

    sijumpk Peon

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Last edited: Jun 15, 2010
    sijumpk, Jun 15, 2010 IP
  7. roopajyothi

    roopajyothi Active Member

    Messages:
    1,302
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    80
    #7
    Oops! The Guy is talking about showing an image using a Dynamic PHP Page template

    BTW: The Thread Starter imgae.php must look like

    
    
    <?php
    $id = intval($_GET['id']);
    header('Content-Type: image/jpeg');
    
    // i couldn't do after this line
    ?>
    <html><head></head><body>
    <img src="http://www.site.com/img/<?php echo $id; ?>.jpg" />
    <body></html>
    ?>
    
    PHP:
     
    roopajyothi, Jun 15, 2010 IP
  8. jonhyhar

    jonhyhar Active Member

    Messages:
    166
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #8
    thanks it works very well
     
    jonhyhar, Jun 15, 2010 IP