image stored in mysql

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • oll3i
    Contributor
    • Mar 2007
    • 679

    image stored in mysql

    I want to display image from mysql in php page
    but i have headers already sent this is what it says
    will i have to change the included headers file to display images form mysql?

    thank You
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    Post your code and we'll tell you wherre you've gone wrong.

    Comment

    • oll3i
      Contributor
      • Mar 2007
      • 679

      #3
      [code=php]
      public function displayLogo($ID _CLIENT){


      $result=mysql_q uery("SELECT logo,logo_type FROM ".$this->tables['clients']." WHERE ID_CLIENT='$ID_ CLIENT'")or die ("SELECT ERROR:(table clients)".mysql _error());
      $type = MYSQL_RESULT($r esult,0,"logo_t ype");
      $data = MYSQL_RESULT($r esult,0,"logo") ;
      header("Content-type: $type");

      echo $data;
      }
      [/code]

      logo is blob

      then on the site

      <td>
      <? echo $client->displayLogo($I D_CLIENT); ?>
      </td>


      but i get
      Warning: Cannot modify header information - headers already sent by (output started at /home/aa24985/domains/purcon.pl/public_html/exec-jobs/config/vert_menu.php:1 5) in path_here/client.php on line 138
      ‰PNG  IHDRÁ@Ł®ábK GD˙˙˙ ˝§“ pHYs  šśtIME× $ńIDATxÚ íťůsG˛Ç?}÷ôÜŁ ‡KĚe{íÝőFĽˆ÷— íźö‡6>Ö ˇűÍ}OUő~h‘F b×&¶ż„Ä„şŞ¦Şľ Y™Y™9šRJ‘ Áż1ôd $$H !A‚ $HH AB‚ $H A‚„ $$H !A‚˙ž0Ďú€¤ ’H!‘J˘¤BCCi S7‘J˘Łƒh`X¦i˘ ë/ß;ÔžqB‰—ĚÔ‘HĐ ŔÔL4]Ă4Í‘gG C”TH%ŃĐâvC3⟦ aż="BĽě×ĐŹ ăą â~č#Áp0$ #"Ĺs†Â˛,LŰÄMą˜ ¦‰eZo5)$‘ˆˇ@ú ’®ßŤ×HJtMǶmÜ´ ÷gščĆ›e`†!âąT ń\ꚎeY§zţđřD$P ęĐúhńú蚎ahşöÇ &A»Ů¦V«1ě ŮÚݢ^Żˆ€l&ËŤë7 Čć˛čč„Qˆô%ť~‡(Ś ČĺsŚOŚS*•0íßşö †Tv+Ô[uęőz<éJ`&ąLŽŇX ‰b©ČřŘ8†mś<¸v· wi´´mú˝~L, ŮcĹ1&¦&(N ÷iŐ[TjüˇŹišd˛&Ć&p <çÜ礂V«EuŻJ ŁÚ C,Ç"•JaZ&†n „`0Đét@A*ťbbl‚ l!‹k¸¸ž‹ĺZ'o®PŇ n·©V«ôý˜Xş…c:( M!ť~‡v§Ťřx)Ź ‰‰ f.͐Ée0-óXTv+ńřŰ úƒ>ČX¨Ýľu›‹3ĎD „p˛µµĹp8¤^ŻÓď

      etc

      Comment

      • hsriat
        Recognized Expert Top Contributor
        • Jan 2008
        • 1653

        #4
        Similar question was asked earlier by someone. Have a look at this.

        Comment

        • oll3i
          Contributor
          • Mar 2007
          • 679

          #5
          but when i add header("Content-type: $type; charset=windows-1250");
          where the type is
          $type=$client->getLogoType($I D_CLIENT); <--- returns image type

          it tries to download it istead of displaying it

          thank You

          Comment

          • oll3i
            Contributor
            • Mar 2007
            • 679

            #6
            $image = imagecreatefrom string($data); doesnt work neither

            Comment

            • hsriat
              Recognized Expert Top Contributor
              • Jan 2008
              • 1653

              #7
              Originally posted by oll3i
              $image = imagecreatefrom string($data); doesnt work neither
              You have to make a new PHP file for displaying images.

              In that PHP file, give header of image type and print all the image data afterwards.[php]<?php
              //filename: image.php
              if ($_GET['img']=="")
              die ('Invalid Parameter');
              header("Content-type:image/jpeg");//whatever is the extension
              $data = mysql_fetch_arr ay(mysql_query( "SELECT `image` FROM ...... WHERE `id`='".$_GET['img']."'"));
              print($data['image']);
              ?>[/php]And in your HTML file, where you need to display that image, write[HTML]<img src="image.php? img=abc" alt="abc" />[/HTML]

              Comment

              • oll3i
                Contributor
                • Mar 2007
                • 679

                #8
                i have
                [code=php]
                <?
                include('../config/config.php');
                $config = new config();
                $config->mysql_server_c onnect();

                $result=mysql_q uery("SELECT logo_name,logo_ size,logo_type, logo FROM ".$config->tables['clients']." WHERE ID_CLIENT=$ID_C LIENT") or die("SELECT Error(table clients): ".mysql_error() );

                list($name, $type, $size, $data) = mysql_fetch_arr ay($result);

                header("Content-length: $size");
                header("Content-type: $type");
                header("Content-Disposition: attachment; filename=$name" );
                echo $data;

                ?
                [/code]

                but how do i now pass that id_client to that file and display the image

                Comment

                • oll3i
                  Contributor
                  • Mar 2007
                  • 679

                  #9
                  sorry i didnt notice that you actually wrote it :)

                  Comment

                  • oll3i
                    Contributor
                    • Mar 2007
                    • 679

                    #10
                    but still i get X instead of logo

                    Comment

                    • hsriat
                      Recognized Expert Top Contributor
                      • Jan 2008
                      • 1653

                      #11
                      Originally posted by oll3i
                      but still i get X instead of logo
                      Right click on the X thingy, and click on view image.
                      You may see what's the error.

                      Comment

                      • oll3i
                        Contributor
                        • Mar 2007
                        • 679

                        #12
                        it doesnt display the error but i know it passes the right id_client

                        Comment

                        • oll3i
                          Contributor
                          • Mar 2007
                          • 679

                          #13
                          maybe there is something wrong in my download.php file
                          [code=php]
                          include('../config/config.php');
                          $config = new config();
                          $config->mysql_server_c onnect();

                          $result=mysql_q uery("SELECT logo_name,logo_ size,logo_type, logo FROM ".$config->tables['clients']." WHERE ID_CLIENT='$ID_ CLIENT'") or die("SELECT Error(table clients): ".mysql_error() );

                          list($name, $size, $type, $data) = mysql_fetch_arr ay($result);


                          header("Content-length: $size");
                          header("Content-type: $type");
                          header("Content-Disposition: attachment; filename=$name" );

                          echo $data;
                          [/code]

                          Comment

                          • oll3i
                            Contributor
                            • Mar 2007
                            • 679

                            #14
                            okey it works now :) i had mistake in the path to config class
                            thank You a lot for Your help

                            Comment

                            Working...