Image return /print

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • me

    Image return /print

    Hey all,
    well i am also a newbie :)

    i saw this on many sites:
    <img src="somephp.ph p?blabla" width="100">

    how can i make that to?

    i want to reffer to a php file that returns or prints a jpg image and in the
    <img src=must be a php url>

    Best regards M


  • Erwin Moller

    #2
    Re: Image return /print

    me wrote:
    [color=blue]
    > Hey all,
    > well i am also a newbie :)
    >
    > i saw this on many sites:
    > <img src="somephp.ph p?blabla" width="100">
    >
    > how can i make that to?
    >
    > i want to reffer to a php file that returns or prints a jpg image and in
    > the <img src=must be a php url>
    >
    > Best regards M[/color]

    Hi,

    You should somephp.php?bla bla return an image, including the right headers
    for MIME-TYPE and such.
    Should work as you described above.

    The trouble will be generating a script that does that. You will have to do
    some more research on imagelibs in PHP.

    Good luck,
    Erwin Moller

    Comment

    • me

      #3
      Re: Image return /print


      "Erwin Moller"
      <since_humans_r ead_this_I_am_s pammed_too_much @spamyourself.c om> wrote in
      message news:3f780f80$0 $58709$e4fe514c @news.xs4all.nl ...[color=blue]
      > me wrote:
      >[color=green]
      > > Hey all,
      > > well i am also a newbie :)
      > >
      > > i saw this on many sites:
      > > <img src="somephp.ph p?blabla" width="100">
      > >
      > > how can i make that to?
      > >
      > > i want to reffer to a php file that returns or prints a jpg image and in
      > > the <img src=must be a php url>
      > >
      > > Best regards M[/color]
      >
      > Hi,
      >
      > You should somephp.php?bla bla return an image, including the right headers
      > for MIME-TYPE and such.
      > Should work as you described above.
      >
      > The trouble will be generating a script that does that. You will have to[/color]
      do[color=blue]
      > some more research on imagelibs in PHP.
      >
      > Good luck,
      > Erwin Moller[/color]

      Thanks,

      i did some testing with this code:

      header("Contet-type: image/jpeg");
      $theURL="image. jpg";
      if(!($fp=fopen( $theURL,"rb")))
      {
      print("Could not open the URL.");
      exit;
      }
      $contents=fread ($fp,1000000);


      print($contents );
      fclose($fp);


      But must i always set the header("Contet-type: image/jpeg") before the code
      begins or can i make first a musql query orso to get the rigth image and
      then print the header("Contet-type: image/jpeg");?


      Comment

      • Erwin Moller

        #4
        Re: Image return /print

        me wrote:
        [color=blue]
        >
        > "Erwin Moller"
        > <since_humans_r ead_this_I_am_s pammed_too_much @spamyourself.c om> wrote in
        > message news:3f780f80$0 $58709$e4fe514c @news.xs4all.nl ...[color=green]
        >> me wrote:
        >>[color=darkred]
        >> > Hey all,
        >> > well i am also a newbie :)
        >> >
        >> > i saw this on many sites:
        >> > <img src="somephp.ph p?blabla" width="100">
        >> >
        >> > how can i make that to?
        >> >
        >> > i want to reffer to a php file that returns or prints a jpg image and
        >> > in the <img src=must be a php url>
        >> >
        >> > Best regards M[/color]
        >>
        >> Hi,
        >>
        >> You should somephp.php?bla bla return an image, including the right
        >> headers for MIME-TYPE and such.
        >> Should work as you described above.
        >>
        >> The trouble will be generating a script that does that. You will have to[/color]
        > do[color=green]
        >> some more research on imagelibs in PHP.
        >>
        >> Good luck,
        >> Erwin Moller[/color]
        >
        > Thanks,
        >
        > i did some testing with this code:
        >
        > header("Contet-type: image/jpeg");[/color]

        that is content-type, no contet-type.
        [color=blue]
        > $theURL="image. jpg";
        > if(!($fp=fopen( $theURL,"rb")))
        > {
        > print("Could not open the URL.");[/color]

        this is a bit odd. You have set the header to image, but your output is
        plain text..
        Not good.

        Your html-page is asking for an image, and your script should return one.
        In your case, where it cannot find the right image, try to send back an
        image you know that exists containing "NOT AVAILABLE" written on it or
        somethinf like that.
        Do not send plain text to the browser when it expects an image.
        Better write an error to some logfile.
        [color=blue]
        > exit;
        > }
        > $contents=fread ($fp,1000000);
        >
        >
        > print($contents );
        > fclose($fp);
        >
        >
        > But must i always set the header("Contet-type: image/jpeg") before the
        > code begins or can i make first a musql query orso to get the rigth image
        > and then print the header("Contet-type: image/jpeg");?[/color]

        You can do whatever you like AS LONG AS YOU DO NOT GENERATE OUTPUT.
        :-)
        The headers should come first.

        Comment

        • Tom Thackrey

          #5
          Re: Image return /print


          On 29-Sep-2003, "me" <someone@micros oft.com> wrote:
          [color=blue]
          > i saw this on many sites:
          > <img src="somephp.ph p?blabla" width="100">
          >
          > how can i make that to?[/color]

          <img src="getimage.p hp?fn=image1" ...>

          getimage.php:
          <?php

          if (isset($_GET['fn']))
          $image = $_GET['fn'];
          else
          $image = 'error';

          header("Content-Type: image/jpeg\n");
          header("Content-Transfer-Encoding: binary");

          $fp=fopen("imag es/$image.jpg" , "r");
          if ($fp)
          fpassthru($fp);

          ?>


          --
          Tom Thackrey

          Comment

          • Jason

            #6
            Re: Image return /print


            "me" <someone@micros oft.com> wrote in message
            news:YvUdb.3918 62$0W5.11564308 @pollux.casema. net...[color=blue]
            >
            > "Erwin Moller"
            > <since_humans_r ead_this_I_am_s pammed_too_much @spamyourself.c om> wrote in
            > message news:3f780f80$0 $58709$e4fe514c @news.xs4all.nl ...[color=green]
            > > me wrote:
            > >[color=darkred]
            > > > Hey all,
            > > > well i am also a newbie :)
            > > >
            > > > i saw this on many sites:
            > > > <img src="somephp.ph p?blabla" width="100">
            > > >
            > > > how can i make that to?
            > > >
            > > > i want to reffer to a php file that returns or prints a jpg image and[/color][/color][/color]
            in[color=blue][color=green][color=darkred]
            > > > the <img src=must be a php url>
            > > >
            > > > Best regards M[/color]
            > >
            > > Hi,
            > >
            > > You should somephp.php?bla bla return an image, including the right[/color][/color]
            headers[color=blue][color=green]
            > > for MIME-TYPE and such.
            > > Should work as you described above.
            > >
            > > The trouble will be generating a script that does that. You will have to[/color]
            > do[color=green]
            > > some more research on imagelibs in PHP.
            > >
            > > Good luck,
            > > Erwin Moller[/color]
            >
            > Thanks,
            >
            > i did some testing with this code:
            >
            > header("Contet-type: image/jpeg");
            > $theURL="image. jpg";
            > if(!($fp=fopen( $theURL,"rb")))
            > {
            > print("Could not open the URL.");
            > exit;
            > }
            > $contents=fread ($fp,1000000);
            >
            >
            > print($contents );
            > fclose($fp);
            >
            >
            > But must i always set the header("Contet-type: image/jpeg") before the[/color]
            code[color=blue]
            > begins or can i make first a musql query orso to get the rigth image and
            > then print the header("Contet-type: image/jpeg");?
            >
            >
            >[/color]

            Maybe try "Content-type" and not "Contet-type" :)


            Comment

            • Allan Savolainen

              #7
              Re: Image return /print

              On Mon, 29 Sep 2003 15:54:32 GMT, "Tom Thackrey"
              <tomnr@creati ve-light.com> wrote:[color=blue]
              ><img src="getimage.p hp?fn=image1" ...>
              >
              >getimage.php :
              ><?php
              >
              >if (isset($_GET['fn']))
              > $image = $_GET['fn'];
              >else
              > $image = 'error';
              >
              >header("Conten t-Type: image/jpeg\n");
              >header("Conten t-Transfer-Encoding: binary");
              >
              >$fp=fopen("ima ges/$image.jpg" , "r");
              >if ($fp)
              > fpassthru($fp);
              >
              >?>[/color]

              another way to do it:

              getimage.php:
              <?php
              if (isset($_GET['fn']))
              {
              $image = $_GET['fn'];
              header("Locatio n: images/$image.jpg");
              }
              else
              {
              header("HTTP/1.0 404 Not Found");
              }
              ?>

              - allan savolainen

              Comment

              • Erwin Moller

                #8
                Re: Image return /print

                Jason wrote:
                [color=blue]
                >
                > "me" <someone@micros oft.com> wrote in message
                > news:YvUdb.3918 62$0W5.11564308 @pollux.casema. net...[color=green]
                >>
                >> "Erwin Moller"
                >> <since_humans_r ead_this_I_am_s pammed_too_much @spamyourself.c om> wrote in
                >> message news:3f780f80$0 $58709$e4fe514c @news.xs4all.nl ...[color=darkred]
                >> > me wrote:
                >> >
                >> > > Hey all,
                >> > > well i am also a newbie :)
                >> > >
                >> > > i saw this on many sites:
                >> > > <img src="somephp.ph p?blabla" width="100">
                >> > >
                >> > > how can i make that to?
                >> > >
                >> > > i want to reffer to a php file that returns or prints a jpg image and[/color][/color]
                > in[color=green][color=darkred]
                >> > > the <img src=must be a php url>
                >> > >
                >> > > Best regards M
                >> >
                >> > Hi,
                >> >
                >> > You should somephp.php?bla bla return an image, including the right[/color][/color]
                > headers[color=green][color=darkred]
                >> > for MIME-TYPE and such.
                >> > Should work as you described above.
                >> >
                >> > The trouble will be generating a script that does that. You will have
                >> > to[/color]
                >> do[color=darkred]
                >> > some more research on imagelibs in PHP.
                >> >
                >> > Good luck,
                >> > Erwin Moller[/color]
                >>
                >> Thanks,
                >>
                >> i did some testing with this code:
                >>
                >> header("Contet-type: image/jpeg");
                >> $theURL="image. jpg";
                >> if(!($fp=fopen( $theURL,"rb")))
                >> {
                >> print("Could not open the URL.");
                >> exit;
                >> }
                >> $contents=fread ($fp,1000000);
                >>
                >>
                >> print($contents );
                >> fclose($fp);
                >>
                >>
                >> But must i always set the header("Contet-type: image/jpeg") before the[/color]
                > code[color=green]
                >> begins or can i make first a musql query orso to get the rigth image and
                >> then print the header("Contet-type: image/jpeg");?
                >>
                >>
                >>[/color]
                >
                > Maybe try "Content-type" and not "Contet-type" :)[/color]

                Hi Jason,

                That might help maybe. ;-)

                Comment

                Working...