15 Replies Latest reply on Aug 7, 2007 4:00 AM by Newsgroup_User

    Uploading an image or picture

    dreamnew Level 1
      Hi,

      I have a contact information form set up for users where they can enter a picture/image along with the text. You can browse your hard drive for the file, but when it uploads to MySQL, you see the file name in the table (i.e. c:\files\pictures\picture.jpg) but instead of the image displaying when you view the data on the webpage, it displays the file path (above). Any ideas how to get the image to display? Is the upload not working correctly maybe? I have the MySQL field set to varchar and the on the form, it's set to text.

      Thanks.
        • 1. Re: Uploading an image or picture
          Level 7
          You are not using the data from the table correctly. It would need to be
          applied to the src attribute of the image tag for you to see the image on
          the page.

          Click where you want the image to appear, INSERT | image > Data sources >
          select the field containing the image name (you may need to adjust the path
          depending on how much you saved with the name).

          --
          Murray --- ICQ 71997575
          Adobe Community Expert
          (If you *MUST* email me, don't LAUGH when you do so!)
          ==================
          http://www.dreamweavermx-templates.com - Template Triage!
          http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
          http://www.dwfaq.com - DW FAQs, Tutorials & Resources
          http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
          ==================


          "dreamnew" <webforumsuser@macromedia.com> wrote in message
          news:f94tt2$fh0$1@forums.macromedia.com...
          > Hi,
          >
          > I have a contact information form set up for users where they can enter a
          > picture/image along with the text. You can browse your hard drive for the
          > file,
          > but when it uploads to MySQL, you see the file name in the table (i.e.
          > c:\files\pictures\picture.jpg) but instead of the image displaying when
          > you
          > view the data on the webpage, it displays the file path (above). Any ideas
          > how
          > to get the image to display? Is the upload not working correctly maybe? I
          > have
          > the MySQL field set to varchar and the on the form, it's set to text.
          >
          > Thanks.
          >

          • 2. Re: Uploading an image or picture
            dreamnew Level 1
            Hi Murray,

            I made the changes you suggested on my display page/form, but all that shows up is the "alt" text, not the image. I've included my code. Is there something I need to do on the database or collection form also?
            • 3. Re: Uploading an image or picture
              Level 7
              Where are you expecting the images to show in the code you posted, and
              please give me an example of the contents of the field in the database, as
              well as what you would see if you have made a static link to that image in
              your HTML.

              --
              Murray --- ICQ 71997575
              Adobe Community Expert
              (If you *MUST* email me, don't LAUGH when you do so!)
              ==================
              http://www.dreamweavermx-templates.com - Template Triage!
              http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
              http://www.dwfaq.com - DW FAQs, Tutorials & Resources
              http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
              ==================


              "dreamnew" <webforumsuser@macromedia.com> wrote in message
              news:f95ejv$3q9$1@forums.macromedia.com...
              > Hi Murray,
              >
              > I made the changes you suggested on my display page/form, but all that
              > shows
              > up is the "alt" text, not the image. I've included my code. Is there
              > something
              > I need to do on the database or collection form also?
              >
              > <form action="" method="get" name="srchdisplay" id="srchdisplay">
              > <table width="100%" border="1" align="center" cellpadding="0"
              > cellspacing="1" bordercolor="#001C00" class="style2" id="srchresult">
              > <?php do { ?>
              > <tr>
              > <td><?php echo $row_business_directory['bname']; ?></td>
              > <td><img src="<?php echo $row_business_directory['picture']; ?>"
              > alt="busimage" /></td>
              > </tr>
              > <tr>
              > <td>Address:</td>
              > <td><?php echo $row_business_directory['street']; ?> <?php echo
              > $row_business_directory['city']; ?>, <?php echo
              > $row_business_directory['state']; ?> <?php echo
              > $row_business_directory['zip'];
              > ?> , <?php echo $row_business_directory['country']; ?></td>
              > </tr>
              >


              • 4. Re: Uploading an image or picture
                dreamnew Level 1
                The code represents the search results page. It's a table where depending on what the user input on the search page, records are displayed from the MySQL db. It should display the business name, with picture or image beside it, further contact information (address, city, state, etc.) in subsequent rows of the table.

                Sorry, I don't understand the part about the static link. This whole page assumes a user would come to a contacts page, input their business contact info, including an image and using a file field, browse their hard drive and attach an image along with the text. This image is (hopefully) stored in the MySQL db along with the other stuff and when someone else comes along and wants to search, the contact info along with image would be pulled from the db and displayed.

                Hope I'm making sense, this is all still a bit difficult to grasp.
                • 5. Re: Uploading an image or picture
                  Level 7
                  On Sun, 5 Aug 2007 16:29:22 +0000 (UTC), "dreamnew"
                  <webforumsuser@macromedia.com> wrote:

                  > I have a contact information form set up for users where they can enter a
                  >picture/image along with the text. You can browse your hard drive for the file,
                  >but when it uploads to MySQL, you see the file name in the table (i.e.
                  >c:\files\pictures\picture.jpg)

                  Someone would have to see the code that processes the form to be able to
                  answer. In short, that code must copy the uploaded file from PHP's
                  temporary directory to a permanent storage location. If you don't do
                  that, then the file is automatically deleted from the temporary
                  directory when the script completes and the file is lost.

                  Gary
                  • 6. Re: Uploading an image or picture
                    dreamnew Level 1
                    I've included the PHP code for the form that collects the user input. For the "Insert Record" server behavior, I have the picture submitted as form "text" since that seemed to be the only option that made sense as it's a file upload. Thanks.
                    • 7. Re: Uploading an image or picture
                      Level 7
                      On Mon, 6 Aug 2007 11:48:03 +0000 (UTC), "dreamnew"
                      <webforumsuser@macromedia.com> wrote:

                      >I've included the PHP code for the form that collects the user input. For the
                      >"Insert Record" server behavior, I have the picture submitted as form "text"
                      >since that seemed to be the only option that made sense as it's a file upload.
                      >Thanks.

                      Unfortunately, the web forum software truncated the code, but that's not
                      the code I need to see. What I need is the code above the <html> and
                      doctype that processes the form.

                      Gary
                      • 8. Re: Uploading an image or picture
                        dreamnew Level 1
                        Sorry, I've attached the code requested below. Thanks again.
                        • 9. Re: Uploading an image or picture
                          Level 7
                          On Mon, 6 Aug 2007 14:17:02 +0000 (UTC), "dreamnew"
                          <webforumsuser@macromedia.com> wrote:

                          I'm assuming that the file field is named 'busimage'. If so:

                          Change this:
                          >GetSQLValueString($_POST['busimage'], "text"));

                          To this:
                          GetSQLValueString($_FILES['busimage']['name'], "text"));

                          And change this:
                          >$Result1 = mysql_query($insertSQL, $MySQL_Biz) or die(mysql_error());

                          To this:
                          $Result1 = mysql_query($insertSQL, $MySQL_Biz) or die(mysql_error());
                          if($_FILES['busimage']['size']>0){
                          $source=$_FILES['busimage']['tmp_name'];

                          // you need to modify the next line
                          $dir='/images/busimage/';

                          $dest=$_SERVER['DOCUMENT_ROOT'].$dir.$_FILES['busimage']['name'];
                          if(!move_uploaded_file($source, $dest))
                          die("Unable to save uploaded image.");
                          }

                          You will need to modify this line:

                          $dir='/images/busimage/';

                          That should point to a site root relative path to the directory where
                          you want the images stored and should, as above, include the trailing
                          slash.
                          • 10. Re: Uploading an image or picture
                            dreamnew Level 1
                            Thank you so much for your help. I edited the code and created the directory (tmp/images) to store. I did a test and the upload works, I see the file in my MySQL db and in the directory on my server, but when I try to display that file, only the words (the name of the image) appear in my display form. Form code here and modified upload form code attached.

                            <form action="" method="get" name="srchdisplay" id="srchdisplay">
                            <table width="100%" border="1" align="center" cellpadding="0" cellspacing="1" bordercolor="#001C00" class="style2" id="srchresult">
                            <?php do { ?>
                            <tr>
                            <td><?php echo $row_business_directory['bname']; ?></td>
                            <td><img src="<?php echo $row_business_directory['picture']; ?>" alt="busimage" /></td>
                            </tr>
                            <tr>
                            <td>Address:</td>
                            • 11. Re: Uploading an image or picture
                              Level 7
                              On Mon, 6 Aug 2007 18:22:45 +0000 (UTC), "dreamnew"
                              <webforumsuser@macromedia.com> wrote:

                              > <td><img src="<?php echo $row_business_directory['picture']; ?>"
                              >alt="busimage" /></td>

                              Is the field name (in the database) picture? Try changing the above to:

                              <td><img src="/tmp/images/<?php echo
                              $row_business_directory['picture']; ?>"
                              alt="busimage" /></td>
                              • 12. Re: Uploading an image or picture
                                dreamnew Level 1
                                Yes, picture is the name of the field in the db and unfortunately, still no luck displaying the image...
                                • 13. Re: Uploading an image or picture
                                  dreamnew Level 1
                                  Thanks to Gary and Murray for all your help and for spending so much time on this. Somehow, through some tweaking that I can't even recount, I got it to work. Wouldn't have been able to do it without you pointing me in the right direction.
                                  • 14. Re: Uploading an image or picture
                                    Level 7
                                    On Mon, 6 Aug 2007 23:49:26 +0000 (UTC), "dreamnew"
                                    <webforumsuser@macromedia.com> wrote:

                                    >Thanks to Gary and Murray for all your help and for spending so much time on
                                    >this. Somehow, through some tweaking that I can't even recount, I got it to
                                    >work. Wouldn't have been able to do it without you pointing me in the right
                                    >direction.

                                    You're welcome. Glad you got it sorted.
                                    • 15. Re: Uploading an image or picture
                                      Level 7
                                      Glad Gary was able to help you! 8)

                                      --
                                      Murray --- ICQ 71997575
                                      Adobe Community Expert
                                      (If you *MUST* email me, don't LAUGH when you do so!)
                                      ==================
                                      http://www.dreamweavermx-templates.com - Template Triage!
                                      http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
                                      http://www.dwfaq.com - DW FAQs, Tutorials & Resources
                                      http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
                                      ==================


                                      "Gary White" <reply@newsgroup.please> wrote in message
                                      news:33vfb3l7n1tbh0gs4l9dpa6bb7tvujpirj@4ax.com...
                                      > On Mon, 6 Aug 2007 23:49:26 +0000 (UTC), "dreamnew"
                                      > <webforumsuser@macromedia.com> wrote:
                                      >
                                      >>Thanks to Gary and Murray for all your help and for spending so much time
                                      >>on
                                      >>this. Somehow, through some tweaking that I can't even recount, I got it
                                      >>to
                                      >>work. Wouldn't have been able to do it without you pointing me in the
                                      >>right
                                      >>direction.
                                      >
                                      > You're welcome. Glad you got it sorted.