retrieve image from MySQL with php error

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

    retrieve image from MySQL with php error

    the script that show image is :

    <?php
    include('dbinfo .inc.php');

    mysql_connect($ localhost,$user name,$password) ;
    @mysql_select_d b($database) or die( "Unable to select database");
    $query = "SELECT file,filesize,f iletype FROM user WHERE id=1;";
    $result=mysql_q uery($query);
    mysql_close();

    $file=mysql_res ult($result,0," file");
    $filesize=mysql _result($result ,0,"filesize") ;
    $filetype=mysql _result($result ,0,"filetype") ;

    header('Content-Type: '.$filetype);
    header("Content-Disposition: attachement\n") ;
    print $file;
    ?>

    it's work fine execpt it show the image as a attachement
    (Save as... window), so Apache, mysql, php seem to work fine.
    the problem is only on http header of image i think.
    i want the image directly so, i use this :

    <?php
    include('dbinfo .inc.php');

    mysql_connect($ localhost,$user name,$password) ;
    @mysql_select_d b($database) or die( "Unable to select database");
    $query = "SELECT file,filesize,f iletype FROM user WHERE id=1;";
    $result=mysql_q uery($query);
    mysql_close();

    $file=mysql_res ult($result,0," file");
    $filesize=mysql _result($result ,0,"filesize") ;
    $filetype=mysql _result($result ,0,"filetype") ;

    header('Content-Type: '.$filetype);
    print $file;
    ?>

    it's don't work, firefox gave me "The image

    cannot be displayed, because it contains error."
    IE show me nothing at all.

    any one have a idea ?

    ----------------------------------------------------
    Windows NT 5.1 build 2600 (XP Professional English)
    Apache 2.0.54, running as a server
    PHP Version 5.0.4 running as module
    MySQL 4.1.7 (a dll from php)
    Firefox english 1.0.4
    Internet Explorer 6

    theonlydrayk@gm ail.com

  • ZeldorBlat

    #2
    Re: retrieve image from MySQL with php error



    theonlydrayk@gm ail.com wrote:[color=blue]
    > the script that show image is :
    >
    > <?php
    > include('dbinfo .inc.php');
    >
    > mysql_connect($ localhost,$user name,$password) ;
    > @mysql_select_d b($database) or die( "Unable to select database");
    > $query = "SELECT file,filesize,f iletype FROM user WHERE id=1;";
    > $result=mysql_q uery($query);
    > mysql_close();
    >
    > $file=mysql_res ult($result,0," file");
    > $filesize=mysql _result($result ,0,"filesize") ;
    > $filetype=mysql _result($result ,0,"filetype") ;
    >
    > header('Content-Type: '.$filetype);
    > header("Content-Disposition: attachement\n") ;
    > print $file;
    > ?>
    >
    > it's work fine execpt it show the image as a attachement
    > (Save as... window), so Apache, mysql, php seem to work fine.
    > the problem is only on http header of image i think.
    > i want the image directly so, i use this :
    >
    > <?php
    > include('dbinfo .inc.php');
    >
    > mysql_connect($ localhost,$user name,$password) ;
    > @mysql_select_d b($database) or die( "Unable to select database");
    > $query = "SELECT file,filesize,f iletype FROM user WHERE id=1;";
    > $result=mysql_q uery($query);
    > mysql_close();
    >
    > $file=mysql_res ult($result,0," file");
    > $filesize=mysql _result($result ,0,"filesize") ;
    > $filetype=mysql _result($result ,0,"filetype") ;
    >
    > header('Content-Type: '.$filetype);
    > print $file;
    > ?>
    >
    > it's don't work, firefox gave me "The image
    > http://ip:8080/viewimage.php
    > cannot be displayed, because it contains error."
    > IE show me nothing at all.
    >
    > any one have a idea ?
    >
    > ----------------------------------------------------
    > Windows NT 5.1 build 2600 (XP Professional English)
    > Apache 2.0.54, running as a server
    > PHP Version 5.0.4 running as module
    > MySQL 4.1.7 (a dll from php)
    > Firefox english 1.0.4
    > Internet Explorer 6
    >
    > theonlydrayk@gm ail.com[/color]

    The content-type is more than just the file extension. Here are some
    common ones for images:

    image/gif
    image/jpeg
    image/bmp
    image/png

    Here's a decent list to check out:



    Comment

    • theonlydrayk@gmail.com

      #3
      Re: retrieve image from MySQL with php error

      yeah i know, the file type is ok, since it work as attachement

      Comment

      • Andy Hassall

        #4
        Re: retrieve image from MySQL with php error

        On 6 Jun 2005 14:38:43 -0700, "ZeldorBlat " <zeldorblat@gma il.com> wrote:
        [color=blue]
        >The content-type is more than just the file extension. Here are some
        >common ones for images:
        >
        >image/gif
        >image/jpeg
        >image/bmp
        >image/png
        >
        >Here's a decent list to check out:
        >
        >http://www.utoronto.ca/webdocs/HTMLd...type.html#imag[/color]

        And for comparison here's the Official list - which (by definition) doesn't
        cover the "type/x-something" values



        --
        Andy Hassall / <andy@andyh.co. uk> / <http://www.andyh.co.uk >
        <http://www.andyhsoftwa re.co.uk/space> Space: disk usage analysis tool

        Comment

        • Andy Hassall

          #5
          Re: retrieve image from MySQL with php error

          On 6 Jun 2005 13:18:19 -0700, "theonlydrayk@g mail.com" <theonlydrayk@g mail.com>
          wrote:
          [color=blue]
          ><?php
          > include('dbinfo .inc.php');
          >
          > mysql_connect($ localhost,$user name,$password) ;
          > @mysql_select_d b($database) or die( "Unable to select database");
          > $query = "SELECT file,filesize,f iletype FROM user WHERE id=1;";
          > $result=mysql_q uery($query);
          > mysql_close();
          >
          > $file=mysql_res ult($result,0," file");
          > $filesize=mysql _result($result ,0,"filesize") ;
          > $filetype=mysql _result($result ,0,"filetype") ;
          >
          > header('Content-Type: '.$filetype);
          > print $file;
          >?>
          >
          >it's don't work, firefox gave me "The image
          >http://ip:8080/viewimage.php
          >cannot be displayed, because it contains error."
          >IE show me nothing at all.
          >
          >any one have a idea ?[/color]

          One trick to debugging dynamic generation of images is to add in a
          header("Content-type: text/plain"), so you can see the output.

          A common error is that there is blank space, or even an error or warning
          message produced, which the browser then tries (and fails) to interpret as
          image data. When displayed as text you can see this.

          --
          Andy Hassall / <andy@andyh.co. uk> / <http://www.andyh.co.uk >
          <http://www.andyhsoftwa re.co.uk/space> Space: disk usage analysis tool

          Comment

          • theonlydrayk@gmail.com

            #6
            Re: retrieve image from MySQL with php error

            with :
            <?php

            include('dbinfo .inc.php');

            mysql_connect($ localhost,$user name,$password) ;
            @mysql_select_d b($database) or die( "Unable to select database");
            $query = "SELECT file,filesize,f iletype FROM user WHERE id=1;";
            $result=mysql_q uery($query);
            mysql_close();

            $file=mysql_res ult($result,0," file");
            $filesize=mysql _result($result ,0,"filesize") ;
            $filetype=mysql _result($result ,0,"filetype") ;

            header('Content-Type: text/plain');
            print $file;
            ?>
            it's open a window save as...viewimage. php
            i rename the file to viewimage.jpg it's the image i want to show
            try it maybe it will help


            Comment

            • Andy Hassall

              #7
              Re: retrieve image from MySQL with php error

              On 6 Jun 2005 15:15:41 -0700, "theonlydrayk@g mail.com" <theonlydrayk@g mail.com>
              wrote:
              [color=blue]
              >with :
              ><?php
              >
              > include('dbinfo .inc.php');
              >
              > mysql_connect($ localhost,$user name,$password) ;
              > @mysql_select_d b($database) or die( "Unable to select database");
              > $query = "SELECT file,filesize,f iletype FROM user WHERE id=1;";
              > $result=mysql_q uery($query);
              > mysql_close();
              >
              > $file=mysql_res ult($result,0," file");
              > $filesize=mysql _result($result ,0,"filesize") ;
              > $filetype=mysql _result($result ,0,"filetype") ;
              >
              > header('Content-Type: text/plain');
              > print $file;
              >?>
              >it's open a window save as...viewimage. php
              >i rename the file to viewimage.jpg it's the image i want to show
              >try it maybe it will help
              >http://24.203.86.30:8080/viewimage.php[/color]

              andyh@server:~/tmp$ GET http://24.203.86.30:8080/viewimage.php | hexdump -C -n
              128
              00000000 20 ff d8 ff e0 00 10 4a 46 49 46 00 01 02 00 00 | ÿØÿà..JFIF..... |
              00000010 64 00 64 00 00 ff ec 00 11 44 75 63 6b 79 00 01 |d.d..ÿì..Ducky ..|
              00000020 00 04 00 00 00 50 00 00 ff ee 00 26 41 64 6f 62 |.....P..ÿî.&Ad ob|
              00000030 65 00 64 c0 00 00 00 01 03 00 15 04 03 06 0a 0d |e.dÀ.......... ..|
              00000040 00 01 6a a1 00 02 35 06 00 03 ea af 00 07 01 da |..j¡..5...ê¯.. .Ú|
              00000050 ff db 00 84 00 02 02 02 02 02 02 02 02 02 02 03 |ÿÛ............ ..|
              00000060 02 02 02 03 04 03 02 02 03 04 05 04 04 04 04 04 |.............. ..|
              00000070 05 06 05 05 05 05 05 05 06 06 07 07 08 07 07 06 |.............. ..|
              00000080

              JFIF is supposed to start with the SOI marker "ff d8" - you've got a leading
              20 - which is a space character.

              Check your source code for a space - I would particularly check dbinfo.inc.php
              as there doesn't appear to be a space in the code you posted.

              --
              Andy Hassall / <andy@andyh.co. uk> / <http://www.andyh.co.uk >
              <http://www.andyhsoftwa re.co.uk/space> Space: disk usage analysis tool

              Comment

              • theonlydrayk@gmail.com

                #8
                Re: retrieve image from MySQL with php error

                ok thanks a lot
                i was a tralling space after the <?php ?> in dbinfo.inc.php

                Comment

                Working...