php coding on how display picture

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kirubagari
    New Member
    • Jun 2007
    • 158

    php coding on how display picture

    Can anyone help me on how display image...i already upload but cannot view or display the image....please help on it
  • MarkoKlacar
    Recognized Expert Contributor
    • Aug 2007
    • 296

    #2
    Hi,

    Where is the image stored, in a database?

    Comment

    • kirubagari
      New Member
      • Jun 2007
      • 158

      #3
      stored in the same folder...not in the database

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        Originally posted by kirubagari
        stored in the same folder...not in the database
        Are you saving anything, at all, in the database? i.e. image locations and urls?

        If not, you should really consider doing this; it will make life much, much easier!

        Comment

        • coolsti
          Contributor
          • Mar 2008
          • 310

          #5
          I am going to give you a sort of complicated tip on how to do something regarding images, but I must say I do not know if this is really what you need here. Depends on what you are trying to do and where the images are located.

          In my case, I was creating images on the fly, so to speak, where my PHP scripts called an external application (in this case Sci-Lab) which created an image from some data, and this image was to be shown on the page.

          The difficulty in my case, and perhaps also in yours, is that the image to be displayed was not located in the "document tree" and so was not accessible to the browser directly. Also in my case I had to create the image and then delete it afterwards.

          What I did was this: In the PHP script that produces the main html code to be sent out to the requester's browser, I include this img tag, here shown using an echo statement:

          echo "<img src=\"image.php \" border=\"0\" >";

          The php script image.php then looks something like this:

          <?php
          $file = "/var/www/scilab/image_to_be_sho wn.gif;
          header("Content-type: image/gif");
          passthru("cat $file");
          // unlink ("$file");
          ?>

          What the above does is this: On your main page, the img tag calls the PHP script image.php as this is specified as the source for the image. The function image.php sends the image file out to the browser using the passthru function. In my case I do not want to keep the image file after it is shown (the image is created by the php code that produces the page), so I uncomment the line with the unlink command.

          (I actually do things more complicated, where I create a random string in the page code and send that string as a GET argument in the img tag, i.e. image.php?ds=$r andomstring, and use this random string as part of the image file name. This lets multiple users access this page at the same time, each creating their own images).

          This method allows you to display an image on your page which is not located in the document tree. If your images are located in the document tree, this way of doing things shouldn't be necessary.

          Steve, Denmark

          Comment

          Working...