24 Replies Latest reply on Feb 27, 2013 9:41 AM by osgood_

    Retrieve an Image for recordset

    Noschlitz Level 1

      After test-uploading data with a form, I can see my image files located in my server directory, and I can see the file name in my sql database.  However, I use the code:

      <td><img src="<?php echo $row_Recordset1['Image']; ?>" alt="No Image to Display" name="" width="120" height="120" /></td>

      and cannot see the image (although I can se the other data) n my recordset.

       

      I have also tried several combinations, like:

      <td><img src="./<?php echo $row_Recordset1['Image']; ?>" alt="If there's an image, it would be here" name="" width="120" height="120" /></td>

      and

      <td><img src="./images/<?php echo $row_Recordset1['Image']; ?>" alt="If there's an image, it would be here" name="" width="120" height="120" /></td>

       

      The placeholder for the image is there...

      It looks like the sql image file name is truncated.  Is there a specific field type, collation or attribute that I should be using instead of varchar, utf8_general__ci?

      Any help would be greatly appreciated.

        • 1. Re: Retrieve an Image for recordset
          bregent Most Valuable Participant

          Can you show us what the code rendered from the browser for one record looks like? That way we can see how the php code is being interpreted.

          • 2. Re: Retrieve an Image for recordset
            Noschlitz Level 1

            Capture.GIFThis is the image that is rendered in each case, although when the image URL is copied (and pasted in a word document), the correct name appears.

            • 3. Re: Retrieve an Image for recordset
              bregent Most Valuable Participant

              No, show us the code, not the image.

              • 4. Re: Retrieve an Image for recordset
                Noschlitz Level 1

                Sorry, here is the code:

                 

                </tr>

                              <tr>

                          <td width="98"><h6>Alabama</h6></td>

                          <td width="97"><h6>set</h6></td>

                          <td width="221" align="left"><h6>set</h6></td>

                          <td><h6><img src="./images/120_0050.JPG" alt="No Image to display" name="" width="120" height="120" /></h6></td>

                          <td width="123"><h6>2013-02-24 16:23:37</h6></td>

                        </tr>

                                <tr>

                          <td width="98"><h6>Alabama</h6></td>

                          <td width="97"><h6>set</h6></td>

                          <td width="221" align="left"><h6>set</h6></td>

                          <td><h6><img src="./images/katie's camera fall 2011 036.JPG" alt="No Image to display" name="" width="120" height="120" /></h6></td>

                          <td width="123"><h6>2013-02-24 16:27:51</h6></td>

                        </tr>

                            </table>

                 

                On the current computer I am on, it displays "No image to display".  On my home computer, it shows the icon (above).

                • 5. Re: Retrieve an Image for recordset
                  bregent Most Valuable Participant

                  You're using document relative referencing for the images. Is the image folder located at the same level as the folder that this page is on?  Or is the page located at the site root?

                  • 6. Re: Retrieve an Image for recordset
                    Noschlitz Level 1

                    I have pasted the structure below.  As you can see, there is one HTML folder.  All other folders reside at the next level, including my images folder. 

                     

                     

                    • 7. Re: Retrieve an Image for recordset
                      Noschlitz Level 1

                      Sending this to supplement the post previously sent.

                      • 8. Re: Retrieve an Image for recordset
                        Noschlitz Level 1

                        The last one didn't seem to work...maybe if I attach it as a word file you

                        can see it to comment on.

                         

                        Thanks

                        • 9. Re: Retrieve an Image for recordset
                          osgood_ Level 8

                          As a test try including the absolute url to the image like below:

                           

                          If locally testing:

                           

                          <img src="localhost/websiteFoldername/imageFolderName/<?php echo $row_Recordset1['Image']; ?>

                           

                          If remote:

                           

                          <img src="http://www.websiteName.com/imageFolderName/<?php echo $row_Recordset1['Image']; ?>

                           

                           

                          If you don't see an image when using the full url then there's something incorrect in your database (check the image name has a .jpg extention).

                           

                          If you do see an image as I expect you should then you have to get the link path to the image correct if you don't want to use the absolute url. It might be ../

                          • 10. Re: Retrieve an Image for recordset
                            bregent Most Valuable Participant

                            >I have pasted the structure below.  As you can see, there is one HTML folder.

                            >All other folders reside at the next level, including my images folder.

                             

                            None of your attachment have worked. Is the php document you are working with located in the site root folder, or in a subfolder?

                            • 11. Re: Retrieve an Image for recordset
                              Noschlitz Level 1

                              Yes, the php document is located in the site root folder. 

                              Additionally, the images folder is located at that same level. 

                              Incidentally, I used the remote testing absolute URL (osgood suggested above), but received the same result.  When inspecing the code, it looks like the correct file is inserted into the code from the mySQL database, just no picture.

                              Frustrating

                              • 12. Re: Retrieve an Image for recordset
                                bregent Most Valuable Participant

                                >Yes, the php document is located in the site root folder. 

                                >Additionally, the images folder is located at that same level.

                                 

                                <img src="./images/katie's camera fall 2011 036.JPG"

                                 

                                 

                                Your path is not correct. If the doc is at root level, that path is telling the browser to move up one level -  which is not valid- before moving down to the image folder. You're better off using root relative paths for this. Just remove the preceeding dot in the path.  If you want to continue using doc relative paths, remove the preceeding dot and slash. You should probably become more familiar with server path syntax. I would also suggest not have filenames with spaces in them.

                                • 13. Re: Retrieve an Image for recordset
                                  osgood_ Level 8

                                  Noschlitz wrote:

                                   

                                  When inspecing the code, it looks like the correct file is inserted into the code from the mySQL database, just no picture.

                                  Frustrating

                                   

                                  So when you view the code you see the absolute path followed by the name of the image?

                                   

                                  You say you are testing remotely. Type the absolute path to this image directly in the browser url bar, does it show up?

                                  • 14. Re: Retrieve an Image for recordset
                                    Noschlitz Level 1

                                    No it does not show up

                                    • 15. Re: Retrieve an Image for recordset
                                      osgood_ Level 8

                                      If it does not show up then its not in the location the link thinks its in.

                                       

                                      As a test make a copy of the image and place it directly in your site folder then do another absolute link test:

                                       

                                      http://www.yourWebsiteAddress.com/nameOfImage.jpg

                                       

                                      If it doesn't show up then there is something wrong with the image (check the color space is saved as RGB and not CMYK)

                                       

                                      If it does show up it means that the path to the image is incorrect in your original test file.

                                      1 person found this helpful
                                      • 16. Re: Retrieve an Image for recordset
                                        Noschlitz Level 1

                                        So locally I have the layout similar to the following:

                                         

                                             -SITE ROOT FOLDER

                                                  -index.php

                                                  -page2.php

                                                  -page3.php...etc,

                                                  -IMAGES FOLDER   

                                                       -image1.jpg

                                                       -image2.jpg

                                                       -UPLOADS FOLDER

                                                            -upload1.jpg

                                                            -upload2.jpg

                                                            -upload3.jpg  etc...

                                         

                                        in my dynamic table, I have

                                         

                                        <td><img src="<?php echo $row_Recordset1['Image']; ?>" alt="If there's an image, it would be here" name="" width="120" height="120" /></td>

                                         

                                        which will take the specified image from Recordset1['Image'] and place it at the end of the designated folder, which locally would be SITE/IMAGES/UPLOADS.  So how does this syntax translate to the server? 

                                         

                                        When I examine the rendering, the file from the database (the image) is correctly identified, and at the end of the string.  So I assume the structure is pointing to a folder that doesn't exist, or as you said, the syntax is incorrect. 

                                         

                                        The Dreamweaver tutorials, and the missing manual do not describe (that I could find) requiring the file path in front of the echo command.  For the most part they indicate that an image placeholder could be set in the dynamic table, and the "Image" recordset bound to that image.    

                                        • 17. Re: Retrieve an Image for recordset
                                          Noschlitz Level 1

                                          Osgood...Wouldn't I need to include the folders as well?  For example

                                           

                                          http://www.yourWebsiteAddress.com/images/uploads/nameOfImage.jpg

                                          • 18. Re: Retrieve an Image for recordset
                                            bregent Most Valuable Participant

                                            Yes, your image source must point to exactly where the image resides. Your browser code showed this:

                                             

                                            <img src="./images/katie's camera fall 2011 036.JPG

                                             

                                            which means you have not embedded the full path in your database - there is no UPLOAD folder in your path. You also need to fix the document relative path problem I mentioned earlier.  Finally, you mention that your images are in a folder named UPLOADS under the  IMAGES folder. But your recordset shows a lowercase 'images' folder. *nix servers are case sensitive so you need to be sure the cases match exactly. So it looks like you have several problems you need to address.

                                            1 person found this helpful
                                            • 19. Re: Retrieve an Image for recordset
                                              Noschlitz Level 1

                                              Osgood, I noticed that when a file is uploaded to the database, the file is truncated, for example 120_035.jpg

                                              The file in the folder on the FTP file manager, however, is 120_0351361934386.jpg

                                               

                                              So, I typed in as you mentioned, first using the truncated file, with no result.

                                              http://www.yourWebsiteAddress.com/120_035.jpg

                                               

                                              Then I did the same with the full file name, with the image shown.

                                              http://www.yourWebsiteAddress.com/120_0351361934386.jpg

                                               

                                              So maybe this is a cause for the situation...but how do I match the file that is uploaded to the file manager, and the name of the file in the database?

                                               

                                              Thanks

                                              • 20. Re: Retrieve an Image for recordset
                                                osgood_ Level 8

                                                Two things may be happening here;

                                                 

                                                1) The column type (Length Value) in your database may not be set to receive as many characters as the image name has. What have you got set?

                                                 

                                                2) How are you uploading the images to the uploads folder? If through a form and upload script the script many be attaching a series of randon numbers to stop images already uploaded with potentially the same name being overwritten.

                                                 

                                                I'd first have a look at what you have set in the Length Value column of your database.

                                                • 21. Re: Retrieve an Image for recordset
                                                  Noschlitz Level 1

                                                  I have it listed as Varchar, 500 characters in length in MySQL.

                                                   

                                                  I purchased a Linecraft image upload package so I did not write any of the script myself, but I assume you're right (to avoid duplicates). 

                                                  • 22. Re: Retrieve an Image for recordset
                                                    osgood_ Level 8

                                                    So are you saying you are manually inserting the image information into the database field as 120_035.jpg

                                                     

                                                    then using the upload facility to select 120_035.jpg and that get uploaded as: 120_0351361934386.jpg

                                                     

                                                    or are you saying the automated upload facility inserts the image name into the database BUT truncates it to 120_035.jpg

                                                    • 23. Re: Retrieve an Image for recordset
                                                      Noschlitz Level 1

                                                      The latter is correct.  I pick a file to upload, click submit, and the image goes to the file with the full name, and the truncated name goes to the datbase. 

                                                      Incidentally, the original name of the file prior to uploading from my machine is 120_035.jpg, not 120_0351361934386.jpg, so that I assume it is elongated to prevent duplication as you said.

                                                      • 24. Re: Retrieve an Image for recordset
                                                        osgood_ Level 8

                                                        Well it appears as though the original uploaded image from your computer 120_035.jpg information is being inserted into the database before the additional numbers are getting added. When the additional numbers have been added the image then gets moved to the upload images folder.

                                                         

                                                        That creates a problem because the recordset only sees 120_035.jpg and not the longer number, so the image can't be found as it no longer exists as 120_035.jpg

                                                         

                                                        You have to try and find a way of not letting the information get uploaded to the database before the extra number have been added.

                                                         

                                                        Was moving the image to the database part of the upload package you bought. If so you will probably have to go back to them and ask why this is happening. Maybe there's a way to stop it adding the random set of numbers to the original image name, which would also solve the issue but then there is the potential for an image to be overwritten. All these upload facilities should come with a error warning anyway if there is a duplicated name in the upload folder.