Show image img src=img.php?img=1.jpg help

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • b007uk@gmail.com

    Show image img src=img.php?img=1.jpg help

    Hi!
    Really need help, dont know whats wrong :(
    I am trying to show images using php script, it works fine, pictures
    are shown,
    but if i right click on it and choose "save picture as" it offers me to
    save it as "untitled.b mp",
    not jpeg the picture actually is :(
    And if i do save it and then check it - it is actually bmp image, not
    jpeg (it has bmp header)
    Could you help please, i need to be able to save it as jpeg, using
    "save picture as".
    here is the script:

    <?php
    if ($_REQUEST['img'])
    {
    $showfile = $_REQUEST['img'];
    if (file_exists($s howfile))
    {
    header("content-type: image/jpeg");
    header('Content-Length: ' . filesize($showf ile));
    $mfile = fopen($showfile , 'rb');
    fpassthru($mfil e);
    fclose($mfile);
    }
    }
    echo "<img src='?img=1.jpg '>";
    ?>

    Thanks a lot!

  • Rik

    #2
    Re: Show image img src=img.php?img =1.jpg help

    b007uk@gmail.co m wrote:[color=blue]
    > header("content-type: image/jpeg");[/color]

    header("Content-Type: image/jpeg");
    header('Content-Disposition: inline; filename=$showf ile");

    Allthough, Disposition isn't really according to standards....

    A brutal read:


    Also, readfile($showf ile) seems faster in this case....

    Grtz,
    --
    Rik Wasmus


    Comment

    • b007uk@gmail.com

      #3
      Re: Show image img src=img.php?img =1.jpg help

      Thank you very much!
      works great! but now i have a different problem, my actual script has
      session_start() ; at the top,
      and it still showing "save picture as" as "untitled.b mp" :(
      if i delete session_start() it shows jpeg, if i add session_start - it
      shows untitled.bmp :(

      Comment

      • RainCT

        #4
        Re: Show image img src=img.php?img =1.jpg help

        Can you copy all the code?

        Comment

        • b007uk@gmail.com

          #5
          Re: Show image img src=img.php?img =1.jpg help


          RainCT wrote:[color=blue]
          > Can you copy all the code?[/color]

          Sure, here it is:

          <?php
          session_start() ;
          $dir = session_id();

          if ($_REQUEST['img'])
          {
          $showfile = "./temp/$dir/".$_REQUEST['img'];

          if (file_exists($s howfile))
          {
          header("content-type: image/jpeg");
          header('Content-Length: ' . filesize($showf ile));
          header("Content-Disposition: inline; filename=$showf ile");
          readfile($showf ile);
          }
          }
          echo "<img src='?img=1.jpg '>";
          ?>

          If i keep session_start() "Save picture as" detects image as
          untitled.bmp, if i delete
          session_start() - everythng is fine, it is detected as jpeg, but i need
          session_id(), so i have to start session...
          And, i read somewhere in this group that i should add ini_set, like
          this:

          <?php
          ini_set('sessio n.use_cookies', '0');
          ini_set('sessio n.cache_limiter ', '');
          ini_set('sessio n.cache_expires ', '');
          session_start() ;
          $dir = session_id();
          .....

          When i do that the image type is detected correctly as jpeg, but the
          file name is not, its named as the script, showimg.jpg,
          filename=$showf ile" is not working for some reason. But i guess its
          good enough, it would be nice to detect the file name as well though

          Comment

          • Jerry Stuckle

            #6
            Re: Show image img src=img.php?img =1.jpg help

            b007uk@gmail.co m wrote:[color=blue]
            > RainCT wrote:
            >[color=green]
            >>Can you copy all the code?[/color]
            >
            >
            > Sure, here it is:
            >
            > <?php
            > session_start() ;
            > $dir = session_id();
            >
            > if ($_REQUEST['img'])
            > {
            > $showfile = "./temp/$dir/".$_REQUEST['img'];
            >
            > if (file_exists($s howfile))
            > {
            > header("content-type: image/jpeg");
            > header('Content-Length: ' . filesize($showf ile));
            > header("Content-Disposition: inline; filename=$showf ile");
            > readfile($showf ile);
            > }
            > }
            > echo "<img src='?img=1.jpg '>";
            > ?>
            >
            > If i keep session_start() "Save picture as" detects image as
            > untitled.bmp, if i delete
            > session_start() - everythng is fine, it is detected as jpeg, but i need
            > session_id(), so i have to start session...
            > And, i read somewhere in this group that i should add ini_set, like
            > this:
            >
            > <?php
            > ini_set('sessio n.use_cookies', '0');
            > ini_set('sessio n.cache_limiter ', '');
            > ini_set('sessio n.cache_expires ', '');
            > session_start() ;
            > $dir = session_id();
            > ....
            >
            > When i do that the image type is detected correctly as jpeg, but the
            > file name is not, its named as the script, showimg.jpg,
            > filename=$showf ile" is not working for some reason. But i guess its
            > good enough, it would be nice to detect the file name as well though
            >[/color]

            But earlier you said this really is a bmp, not a jpg.

            Just changing the name or header is not going to change the real file type. It
            will still be a bmp. If you want to change it to a jpg, you need to convert it
            first.



            --
            =============== ===
            Remove the "x" from my email address
            Jerry Stuckle
            JDS Computer Training Corp.
            jstucklex@attgl obal.net
            =============== ===

            Comment

            • b007uk@gmail.com

              #7
              Re: Show image img src=img.php?img =1.jpg help


              Jerry Stuckle wrote:[color=blue]
              > b007uk@gmail.co m wrote:[color=green]
              > > RainCT wrote:
              > >[color=darkred]
              > >>Can you copy all the code?[/color]
              > >
              > >
              > > Sure, here it is:
              > >
              > > <?php
              > > session_start() ;
              > > $dir = session_id();
              > >
              > > if ($_REQUEST['img'])
              > > {
              > > $showfile = "./temp/$dir/".$_REQUEST['img'];
              > >
              > > if (file_exists($s howfile))
              > > {
              > > header("content-type: image/jpeg");
              > > header('Content-Length: ' . filesize($showf ile));
              > > header("Content-Disposition: inline; filename=$showf ile");
              > > readfile($showf ile);
              > > }
              > > }
              > > echo "<img src='?img=1.jpg '>";
              > > ?>
              > >
              > > If i keep session_start() "Save picture as" detects image as
              > > untitled.bmp, if i delete
              > > session_start() - everythng is fine, it is detected as jpeg, but i need
              > > session_id(), so i have to start session...
              > > And, i read somewhere in this group that i should add ini_set, like
              > > this:
              > >
              > > <?php
              > > ini_set('sessio n.use_cookies', '0');
              > > ini_set('sessio n.cache_limiter ', '');
              > > ini_set('sessio n.cache_expires ', '');
              > > session_start() ;
              > > $dir = session_id();
              > > ....
              > >
              > > When i do that the image type is detected correctly as jpeg, but the
              > > file name is not, its named as the script, showimg.jpg,
              > > filename=$showf ile" is not working for some reason. But i guess its
              > > good enough, it would be nice to detect the file name as well though
              > >[/color]
              >
              > But earlier you said this really is a bmp, not a jpg.
              >
              > Just changing the name or header is not going to change the real file type. It
              > will still be a bmp. If you want to change it to a jpg, you need to convert it
              > first.[/color]

              Yes, i understand that. The picture is jpeg (echo "<img
              src='?img=1.jpg '>";), but "save picture as" only offered to save it as
              bmp, not jpeg, that was my problem/question.

              Comment

              • Jerry Stuckle

                #8
                Re: Show image img src=img.php?img =1.jpg help

                b007uk@gmail.co m wrote:[color=blue]
                > Jerry Stuckle wrote:
                >[color=green]
                >>b007uk@gmail. com wrote:
                >>[color=darkred]
                >>>RainCT wrote:
                >>>
                >>>
                >>>>Can you copy all the code?
                >>>
                >>>
                >>>Sure, here it is:
                >>>
                >>><?php
                >>>session_star t();
                >>>$dir = session_id();
                >>>
                >>>if ($_REQUEST['img'])
                >>>{
                >>>$showfile = "./temp/$dir/".$_REQUEST['img'];
                >>>
                >>> if (file_exists($s howfile))
                >>> {
                >>> header("content-type: image/jpeg");
                >>> header('Content-Length: ' . filesize($showf ile));
                >>> header("Content-Disposition: inline; filename=$showf ile");
                >>> readfile($showf ile);
                >>> }
                >>>}
                >>>echo "<img src='?img=1.jpg '>";
                >>>?>
                >>>
                >>>If i keep session_start() "Save picture as" detects image as
                >>>untitled.bmp , if i delete
                >>>session_star t() - everythng is fine, it is detected as jpeg, but i need
                >>>session_id() , so i have to start session...
                >>>And, i read somewhere in this group that i should add ini_set, like
                >>>this:
                >>>
                >>><?php
                >>>ini_set('ses sion.use_cookie s', '0');
                >>>ini_set('ses sion.cache_limi ter', '');
                >>>ini_set('ses sion.cache_expi res', '');
                >>>session_star t();
                >>>$dir = session_id();
                >>>....
                >>>
                >>>When i do that the image type is detected correctly as jpeg, but the
                >>>file name is not, its named as the script, showimg.jpg,
                >>>filename=$sh owfile" is not working for some reason. But i guess its
                >>>good enough, it would be nice to detect the file name as well though
                >>>[/color]
                >>
                >>But earlier you said this really is a bmp, not a jpg.
                >>
                >>Just changing the name or header is not going to change the real file type. It
                >>will still be a bmp. If you want to change it to a jpg, you need to convert it
                >>first.[/color]
                >
                >
                > Yes, i understand that. The picture is jpeg (echo "<img
                > src='?img=1.jpg '>";), but "save picture as" only offered to save it as
                > bmp, not jpeg, that was my problem/question.
                >[/color]

                OK, I misread your original post. I understand now.

                I haven't actually tried mixing session_start() with header(); normally if I'm
                using header() I don't need session_start() .

                Since both must be sent before anything else is output, I suspect there's a
                conflict between the two. However, what should work is to use an img tag in
                this file, pointing at a file containing your PHP code. In this file send your
                session_start() ; in the other file only send the header and image.

                This works because the img tag causes another request to the server, which
                requires another header.


                --
                =============== ===
                Remove the "x" from my email address
                Jerry Stuckle
                JDS Computer Training Corp.
                jstucklex@attgl obal.net
                =============== ===

                Comment

                • b007uk@gmail.com

                  #9
                  Re: Show image img src=img.php?img =1.jpg help


                  Jerry Stuckle wrote:[color=blue]
                  > b007uk@gmail.co m wrote:[color=green]
                  > > Jerry Stuckle wrote:
                  > >[color=darkred]
                  > >>b007uk@gmail. com wrote:
                  > >>
                  > >>>RainCT wrote:
                  > >>>
                  > >>>
                  > >>>>Can you copy all the code?
                  > >>>
                  > >>>
                  > >>>Sure, here it is:
                  > >>>
                  > >>><?php
                  > >>>session_star t();
                  > >>>$dir = session_id();
                  > >>>
                  > >>>if ($_REQUEST['img'])
                  > >>>{
                  > >>>$showfile = "./temp/$dir/".$_REQUEST['img'];
                  > >>>
                  > >>> if (file_exists($s howfile))
                  > >>> {
                  > >>> header("content-type: image/jpeg");
                  > >>> header('Content-Length: ' . filesize($showf ile));
                  > >>> header("Content-Disposition: inline; filename=$showf ile");
                  > >>> readfile($showf ile);
                  > >>> }
                  > >>>}
                  > >>>echo "<img src='?img=1.jpg '>";
                  > >>>?>
                  > >>>
                  > >>>If i keep session_start() "Save picture as" detects image as
                  > >>>untitled.bmp , if i delete
                  > >>>session_star t() - everythng is fine, it is detected as jpeg, but i need
                  > >>>session_id() , so i have to start session...
                  > >>>And, i read somewhere in this group that i should add ini_set, like
                  > >>>this:
                  > >>>
                  > >>><?php
                  > >>>ini_set('ses sion.use_cookie s', '0');
                  > >>>ini_set('ses sion.cache_limi ter', '');
                  > >>>ini_set('ses sion.cache_expi res', '');
                  > >>>session_star t();
                  > >>>$dir = session_id();
                  > >>>....
                  > >>>
                  > >>>When i do that the image type is detected correctly as jpeg, but the
                  > >>>file name is not, its named as the script, showimg.jpg,
                  > >>>filename=$sh owfile" is not working for some reason. But i guess its
                  > >>>good enough, it would be nice to detect the file name as well though
                  > >>>
                  > >>
                  > >>But earlier you said this really is a bmp, not a jpg.
                  > >>
                  > >>Just changing the name or header is not going to change the real file type. It
                  > >>will still be a bmp. If you want to change it to a jpg, you need to convert it
                  > >>first.[/color]
                  > >
                  > >
                  > > Yes, i understand that. The picture is jpeg (echo "<img
                  > > src='?img=1.jpg '>";), but "save picture as" only offered to save it as
                  > > bmp, not jpeg, that was my problem/question.
                  > >[/color]
                  >
                  > OK, I misread your original post. I understand now.
                  >
                  > I haven't actually tried mixing session_start() with header(); normally if I'm
                  > using header() I don't need session_start() .
                  >
                  > Since both must be sent before anything else is output, I suspect there's a
                  > conflict between the two. However, what should work is to use an img tag in
                  > this file, pointing at a file containing your PHP code. In this file send your
                  > session_start() ; in the other file only send the header and image.
                  >
                  > This works because the img tag causes another request to the server, which
                  > requires another header.[/color]

                  Thank you very much!
                  It sounds like a great idea, i don't fully understand how its going to
                  work, but ill figure it out.
                  My main concern is to be able to hide the actual path to the image file
                  ($showfile = "./temp/$dir/".$_REQUEST['img'];) so it would not be
                  anywhere in the html, and to make sure the file can only be downloaded
                  once, by the person with the correct session id

                  Comment

                  • Jerry Stuckle

                    #10
                    Re: Show image img src=img.php?img =1.jpg help

                    b007uk@gmail.co m wrote:[color=blue]
                    > Jerry Stuckle wrote:
                    >[color=green]
                    >>b007uk@gmail. com wrote:
                    >>[color=darkred]
                    >>>Jerry Stuckle wrote:
                    >>>
                    >>>
                    >>>>b007uk@gmai l.com wrote:
                    >>>>
                    >>>>
                    >>>>>RainCT wrote:
                    >>>>>
                    >>>>>
                    >>>>>
                    >>>>>>Can you copy all the code?
                    >>>>>
                    >>>>>
                    >>>>>Sure, here it is:
                    >>>>>
                    >>>>><?php
                    >>>>>session_st art();
                    >>>>>$dir = session_id();
                    >>>>>
                    >>>>>if ($_REQUEST['img'])
                    >>>>>{
                    >>>>>$showfil e = "./temp/$dir/".$_REQUEST['img'];
                    >>>>>
                    >>>>> if (file_exists($s howfile))
                    >>>>> {
                    >>>>> header("content-type: image/jpeg");
                    >>>>> header('Content-Length: ' . filesize($showf ile));
                    >>>>> header("Content-Disposition: inline; filename=$showf ile");
                    >>>>> readfile($showf ile);
                    >>>>> }
                    >>>>>}
                    >>>>>echo "<img src='?img=1.jpg '>";
                    >>>>>?>
                    >>>>>
                    >>>>>If i keep session_start() "Save picture as" detects image as
                    >>>>>untitled.b mp, if i delete
                    >>>>>session_st art() - everythng is fine, it is detected as jpeg, but i need
                    >>>>>session_id (), so i have to start session...
                    >>>>>And, i read somewhere in this group that i should add ini_set, like
                    >>>>>this:
                    >>>>>
                    >>>>><?php
                    >>>>>ini_set('s ession.use_cook ies', '0');
                    >>>>>ini_set('s ession.cache_li miter', '');
                    >>>>>ini_set('s ession.cache_ex pires', '');
                    >>>>>session_st art();
                    >>>>>$dir = session_id();
                    >>>>>....
                    >>>>>
                    >>>>>When i do that the image type is detected correctly as jpeg, but the
                    >>>>>file name is not, its named as the script, showimg.jpg,
                    >>>>>filename=$ showfile" is not working for some reason. But i guess its
                    >>>>>good enough, it would be nice to detect the file name as well though
                    >>>>>
                    >>>>
                    >>>>But earlier you said this really is a bmp, not a jpg.
                    >>>>
                    >>>>Just changing the name or header is not going to change the real file type. It
                    >>>>will still be a bmp. If you want to change it to a jpg, you need to convert it
                    >>>>first.
                    >>>
                    >>>
                    >>>Yes, i understand that. The picture is jpeg (echo "<img
                    >>>src='?img=1. jpg'>";), but "save picture as" only offered to save it as
                    >>>bmp, not jpeg, that was my problem/question.
                    >>>[/color]
                    >>
                    >>OK, I misread your original post. I understand now.
                    >>
                    >>I haven't actually tried mixing session_start() with header(); normally if I'm
                    >>using header() I don't need session_start() .
                    >>
                    >>Since both must be sent before anything else is output, I suspect there's a
                    >>conflict between the two. However, what should work is to use an img tag in
                    >>this file, pointing at a file containing your PHP code. In this file send your
                    >>session_start (); in the other file only send the header and image.
                    >>
                    >>This works because the img tag causes another request to the server, which
                    >>requires another header.[/color]
                    >
                    >
                    > Thank you very much!
                    > It sounds like a great idea, i don't fully understand how its going to
                    > work, but ill figure it out.
                    > My main concern is to be able to hide the actual path to the image file
                    > ($showfile = "./temp/$dir/".$_REQUEST['img'];) so it would not be
                    > anywhere in the html, and to make sure the file can only be downloaded
                    > once, by the person with the correct session id
                    >[/color]

                    With this method you can't hide the URL completely. You'll still have the path
                    to the php file in the img tag. But you should be able to now add some code to
                    the php file which will limit access to the image.


                    --
                    =============== ===
                    Remove the "x" from my email address
                    Jerry Stuckle
                    JDS Computer Training Corp.
                    jstucklex@attgl obal.net
                    =============== ===

                    Comment

                    Working...