How do I display images from general fields of a table?

Topics: User Forum
Jun 14, 2011 at 3:01 PM

I have just started using Active VFP and it is great getting back to Foxpro.

I have just faced a small problem is that I want to display on the webpage (in a table) images stored into a general field of the dbf file.  How does one do it?

Coordinator
Jun 14, 2011 at 7:36 PM

Most developers store only the name of the image in the database and the actual file stored on disk.  

If you can't do this then I think you can dynamically do a low level file read on the file, copy it to disk and output it that way like any other image.  Going back a ways, here's an article on how to do it:

HOWTO: Export an Embedded .bmp Image into a File

ID: Q161832


--------------------------------------------------------------------------------
The information in this article applies to:

Microsoft Visual FoxPro for Windows, versions 3.0, 3.0b, 5.0, 6.0
Microsoft FoxPro for Macintosh, versions 2.5b, 2.5c, 2.6a
Microsoft Visual FoxPro for Macintosh, version 3.0b

--------------------------------------------------------------------------------


SUMMARY
The command "APPEND GENERAL <General field name> FROM <filename>.bmp" imports a BMP image from a file and places it into a general field. But there is no reverse command like "Copy General To," which can export an embedded BMP image into a .bmp file. The following steps offer a workaround specially designed for embedded .bmp files only, other data formats can be easily exported if the storage structure of an OLE object is recognizable.

MORE INFORMATION
The following steps and sample program can be used to save an embedded bitmap file to a physical file on disk:

Go to the record number of a table that you would like the associated BMP image exported to.


Copy the general field (Name "Picture") of the record to a temporary file (Name "Temp"). So the newly created Temp.dbf file contains one general field "Picture" and one record only. The syntax for this follows:

COPY TO temp FIELDS picture NEXT 1

Execute the following code, assuming the file name for the output BMP image is "Test.Bmp":

*** Open two files, "temp.fpt" contains the physical BMP data.
*** and Create a file handle for the output file "Test.Bmp"
handlein=FOPEN("temp.fpt")
handleout=FCREATE("test.bmp")

*** To determine the length of the Input file "Temp.fpt"
gnEnd = FSEEK(handlein, 0, 2)
gnTop = FSEEK(handlein, 0)

*** Store the whole file into a string "str1"
str1 = FREAD(handlein, gnEnd)

*** Offset 599 bytes from Str1 and save it to "str2"
str2=RIGHT(str1,LEN(str1)-599)

*** Write "Str2" into the BMP file "Test.BMP"
n=FWRITE(handleout,str2)

*** Close both opened files
=FCLOSE(handlein)
=FCLOSE(handleout)

NOTE: If the BMP is placed into a General field by Edit/Paste from Clipboard, the data stored in general field is 599 bytes of header bytes plus the actual BMP data.

If the .bmp file is embedded in a general field by "Insert Object" or "Append General," then FoxPro creates presentation data plus the actual .bmp file data into the general field, which may result in the size of the FTP file being twice as big as the original .bmp data and if this is the case, 599 may not be the correct offset.

Additional query words:

Keywords : kbole kbnokeyword kbMAC kbVFp300 kbVFp500 kbVFp600
Version :
Platform :
Issue type : kbhowto
Technology :


Last Reviewed: August 11, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.


Article ID: Q161832

Last Reviewed:
August 11, 1999

Jun 16, 2011 at 6:33 AM

Hi Claude, and thanks for the prompt reply.

 

I think that I did not make my problem clear as I was too brief.

What is happening is that I have a dbf file with general fields pict1s, pict2s, pict3s and pict4s apart from other fields.  The general fields are linked to jpg files stored separately on disk.  They are accessible when viewed through VFP.  However, when I go do display the fields in the webpage using the following code, all other fields display, but the general fields do not display at all.

The code I am using to display from the cursor tCursor is as follows;

                 
                          <tr>
                            <td width="10%"><font face="helvetica, arial" size="2">
                            <%=tCursor.propcat%></font></td>
                            <td width="66%"><font face="helvetica, arial" size="2">
                            <%=tCursor.desc%></font>
                            <br>
                    <img border="0" src="<%tCursor.pict1s%>"> &nbsp;
                  
                    <img border="0" src="<%tCursor.pict2s%>"> &nbsp;
                   
                    <img border="0" src="<%tCursor.pict3s%>"> &nbsp;
                 
                    <img border="0" src="<%tCursor.pict4s%>"></td>
                            <td width="20%"><font face="helvetica, arial" size="2">
                            <%=tCursor.amount%></font></td>
                          </tr>

Hope that it is clear this time.

 

Rgds

 

Eliot

Coordinator
Jun 16, 2011 at 1:21 PM

So the picture table is not embedded in the general field??   The General field just contains the link?  If this is really true then just get that jpg file name from that field and refer to it directly in the html like /imagesdirectory/pict1s.jpg instead of <%tCursor.pict1s%>.  I believe you're still going to have to do the FREAD stuff mentioned above to get the actual name of the file stored in the General field.

It sounds like you're looking for an easier answer when there isn't one when using a General field.  You're going to have to FREAD that binary file info to get the file name and location.  Just use the instructions given earlier to get the contents of the GENERAL field into a string and see what it says.

Jun 16, 2011 at 1:23 PM

Thanks... seems that it should work.

Will get down to it.

 

Rgds

 

Eliot