Display img sec using PHP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • GeorgeEhr
    New Member
    • Sep 2010
    • 1

    Display img sec using PHP

    I have a database where I store images, or rather paths to images.
    I can display the images using http://www.domain.com/show.php?img=1.jpg&mid=1

    Using that page it shows 4 images in a table 2 side by side and 2 side by side on the next row.

    I want to call the show.php page from another file using the <img src>. Is it even possible?
    Last edited by GeorgeEhr; Sep 15 '10, 01:59 AM. Reason: typo
  • TheServant
    Recognized Expert Top Contributor
    • Feb 2008
    • 1168

    #2
    So I think that you're wanting to dynamically create an image of a page to show in another page using an <img /> tag?

    This is possible using PHP GD Library, although I have never tried. I don't have much time at the moment to research this, but I have given you a few key words to google with. Also read a bit of what the GD Library can do here.

    Comment

    • Canabeez
      New Member
      • Jul 2009
      • 126

      #3
      There's no need to use the GD library if you don't want to combine images. You can dynamically draw them on the page using either PHP of JS.

      If you want to use PHP to output and image, then just:[code="php"]
      <?php
      ob_start();
      $imageId = isset($_GET['img']) ? addslashes($_GE T['img']) : false;

      if(!$imageId){
      exit;
      }

      $result = mysql_query("
      SELECT `image` FROM `images` WHERE `image_id` = {$imageId} LIMIT 1
      ");

      $imageObject = mysql_fetch_obj ect($result);
      $image = $imageObject->image;

      header("Content-Type: " . mime_content_ty pe($image) . ";\n");

      echo file_get_conten ts($image);
      ob_end_flush();
      exit;
      ?>[/code]

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        Canabeez, the output-buffering is redundant there, as you are not outputting anything before the call to header().

        Mark (the Pedantic).

        Comment

        • Canabeez
          New Member
          • Jul 2009
          • 126

          #5
          Thank's Mark, you completely right.

          Comment

          Working...