multi image print

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tolkienarda
    Contributor
    • Dec 2006
    • 316

    multi image print

    Hi all

    below is a function that works to print out one image and my attempt to duplicate it in such a way that i can print multiple images the echo statement is in a loop and i don't know what the header("...") stuff is for but it was in the function is stole this code from

    [PHP]
    if ($_REQUEST[gim] == 1) {
    header("Content-type: image/jpeg"); //don't know what this does
    print $bytes; // bytes has the imgdata from one image stored in it
    exit ();
    }

    //and in the body of the page

    <img src=?gim=1 width=144>
    [/PHP]

    and here is my attempt this is in a loop
    [PHP]

    echo '<img src=" 'header("Conten t-type: image/jpeg"); $row[imgdata];' " '>

    [/PHP]

    thanks for input

    eric
  • Motoma
    Recognized Expert Specialist
    • Jan 2007
    • 3236

    #2
    Originally posted by tolkienarda
    [PHP]

    echo '<img src=" 'header("Conten t-type: image/jpeg"); $row[imgdata];' " '>

    [/PHP]

    thanks for input

    eric
    NOPE.

    What the first script is doing, rather than returning text in the form of HTML, it is returning binary data in the form of a JPEG image.

    That means when you view the php file, and save it, you are saving an Image, rather than a web page.

    It is not possible to embed things the way you are trying to.

    Comment

    • tolkienarda
      Contributor
      • Dec 2006
      • 316

      #3
      ok do you know a good way to display images out of a mysql database. i have done next to nothing with file storage in databases. with the exception of the project i am working on now i have alwasys just done text.

      eric

      Comment

      • Motoma
        Recognized Expert Specialist
        • Jan 2007
        • 3236

        #4
        1. Make a PHP script that, when given an image ID via $_GET, displays an image from the database.

        2. Make a PHP script that prints <img src=...> tags, each one referencing the PHP script above.

        Comment

        • tolkienarda
          Contributor
          • Dec 2006
          • 316

          #5
          ok i will make those and post the results

          thanks much

          eric

          Comment

          • tolkienarda
            Contributor
            • Dec 2006
            • 316

            #6
            ok so i am stupid but here is my question

            when i call this new php page do i do it somthing like this

            newpage(title);

            with newpage being the new php page and title being the variable being sent via GET

            eric

            Comment

            • Motoma
              Recognized Expert Specialist
              • Jan 2007
              • 3236

              #7
              Originally posted by tolkienarda
              ok so i am stupid but here is my question

              when i call this new php page do i do it somthing like this

              newpage(title);

              with newpage being the new php page and title being the variable being sent via GET

              eric
              No, you will create a page called showImage.php.
              When passed an imageid, it will retrieve it from the database and show that picture.
              You will then have your other php page output this:
              [HTML]
              <img src="showImage. php?imageid=5" />
              <img src="showImage. php?imageid=76" />
              <img src="showImage. php?imageid=549 " />
              [/HTML]

              Comment

              • tolkienarda
                Contributor
                • Dec 2006
                • 316

                #8
                ok thanks sorry for the stupid questions

                eric

                Comment

                • Motoma
                  Recognized Expert Specialist
                  • Jan 2007
                  • 3236

                  #9
                  No worries; everyone was a beginner once.

                  Comment

                  • tolkienarda
                    Contributor
                    • Dec 2006
                    • 316

                    #10
                    i hopefully wont be a begginer for long i am going to a week training course in php and i hope that after that and some time applying the stuff they teach me i will be at least an ok programer.

                    eric

                    Comment

                    • tolkienarda
                      Contributor
                      • Dec 2006
                      • 316

                      #11
                      ok i've tried everthing i can think of and it still won't work. below is the code and a link to the page.
                      http://www.steppinupwe bdesign.com/cms/imgupload.php

                      the main part of this script is the imgprint() function it is near the bottom
                      [PHP]
                      if ($_REQUEST[completed] == 1) {
                      // Need to add - check for large upload. Otherwise the code
                      // will just duplicate old file ;-)
                      // ALSO - note that latest.img must be public write and in a
                      // live appliaction should be in another (safe!) directory.
                      move_uploaded_f ile($_FILES['imagefile']['tmp_name'],"latest.img ");
                      $image = addslashes(frea d(fopen ($_FILES['imagefile']['tmp_name'],'r'),filesize( $_FILES['imagefile']['tmp_name'])));
                      if (strlen($instr) < 149000) {
                      mysql_query ("insert into pix (title, imgdata, location) values (\"".
                      $_REQUEST[whatsit].
                      "\", \"".
                      $image.
                      "\")");
                      } else {
                      $errmsg = "Too large!";
                      }
                      }

                      imgprint();//calls the image printer after images are uploaded



                      // If this is the image request, send out the image
                      /*
                      if ($_REQUEST[gim] == 1) {
                      header("Content-type: image/jpeg");
                      print $bytes;
                      exit ();
                      }
                      */
                      ?>

                      <html><head>
                      <title>Upload image</title>
                      <body bgcolor=white>< h2>latest picture</h2>
                      <font color=red><?= $errmsg ?></font>
                      <center><img src=?gim=1 width=144><br>
                      <table>
                      <tr>
                      <td>
                      <?
                      function imgprint()
                      {
                      $result = mysql_query("SE LECT * FROM pix");//this table has an four coloms; title(unique), imgdata, id, location
                      $rowcount = mysql_num_rows( $result);
                      $i = 1;
                      while ($i < $rowcount)
                      {
                      $row = mysql_fetch_row ($result);
                      $title = $row[title];
                      echo '<img src="imagedisp. php?title=$titl e" />';
                      $i++;
                      }
                      }
                      ?>
                      </table>
                      <img src="imagedisp. php?title=asdf" >
                      <b><?= $title ?></center>
                      <form enctype=multipa rt/form-data method=post>
                      <input type=hidden name=MAX_FILE_S IZE value=150000>
                      <input type=hidden name=completed value=1>
                      browse: <input type=file name=imagefile> <br>
                      comments: <input name=whatsit><b r>
                      then: <input type=submit></form><br>


                      </body>
                      </html>
                      [/PHP]

                      and here is imgdisp.php

                      [PHP]

                      $title = $_GET[title];
                      $result = "SELECT imgdata, type FROM pix WHERE title='$title'" ;
                      $Show = mysql ( $hDB, $hSQL );
                      $rows = mysql_num_rows( $hShow);

                      if($rows<1){
                      // no image matches this query
                      }
                      else{
                      // at least one image has this title
                      $getPhoto = mysql_fetch_obj ect($Show);

                      // we need to determine the mime type
                      $Type = $getPhoto->type;

                      // and send the correct header to the browser
                      Header("Content-type: $Type");

                      // now send the image
                      $Body = $getPhoto->body;
                      echo $Body;
                      flush();
                      }
                      [/PHP]

                      thanks eric

                      Comment

                      • Motoma
                        Recognized Expert Specialist
                        • Jan 2007
                        • 3236

                        #12
                        Originally posted by tolkienarda
                        ok i've tried everthing i can think of and it still won't work. below is the code and a link to the page.
                        http://www.steppinupwe bdesign.com/cms/imgupload.php
                        I went to the site, but could not find imagedisp.php which was the src for the img tag.

                        Comment

                        • tolkienarda
                          Contributor
                          • Dec 2006
                          • 316

                          #13
                          crap i am stupid

                          the imgdisp.php file is in a subfolder. ahahahahahah i hate being stupid, so frustrating when i do stuff like this it makes me want to kick myself but i am to fat and can't reach my head. oh well i will have to settle for hitting my head against the moniter.

                          eric

                          Comment

                          • tolkienarda
                            Contributor
                            • Dec 2006
                            • 316

                            #14
                            hi i am troubleshooting this code one line at a time and i am curious as to what this does

                            [PHP]
                            $Show = mysql ( $hDB, $hSQL );
                            [/PHP]

                            it is just below my mysql query

                            eric

                            Comment

                            • Motoma
                              Recognized Expert Specialist
                              • Jan 2007
                              • 3236

                              #15
                              Originally posted by tolkienarda
                              hi i am troubleshooting this code one line at a time and i am curious as to what this does

                              [PHP]
                              $Show = mysql ( $hDB, $hSQL );
                              [/PHP]

                              it is just below my mysql query

                              eric
                              This isn't your code?
                              Spit out $hDB, $hSQL, and $Show. What makes sense?
                              Check the definition of mysql()

                              Comment

                              Working...