Images and local and net

Images and local and net

Post by Bria » Tue, 22 Jul 2003 09:11:56


i all



I have a cross platform problem. I have written a Delphi application that
stores images in a paradox table. I then upload the data to a MySQL table
and want to read the data out and display the image.

Now heres the problem, I can get images to read in and out on the Delphi
application ok. And I have code which will read and write images from a
table via PHP on the net using the MySQL table.



But the images will not work if I upload them via the Delphi application. On
both the paradox table and the MySQL table I am using a blob field.

Below I have shown the code used on both the Delphi program and the PHP code
so you can see what's going on.



Sorry about cross posting this message but its both a Delphi and PHP
problem, any help in any way would be great



Brian





DELPHI PROCEDURES TO ASSIGN THE IMAGES TO THE TABLE AND GET THEM FROM THE
TABLE



procedure TMain.ChangeImageBtnClick(Sender: TObject);

begin

AssignImageTable(Data.gigs.FieldByName('poster'),Poster);

end;



=============================================================



procedure AssignImageTable(table:TField; Image:Timage);

var

JPEG: TJPEGImage;

JPEGStream: TBlobStream;

begin

If Main.OpenPictureDialog.Execute then

begin

try

JPEG := TJPEGImage.Create;

JPEG.LoadFromFile(Main.OpenPictureDialog1.FileName);

Image.Picture.Assign(JPEG);

try

try

JPEGStream := TBlobStream.Create(TBlobField(table),bmWrite);

JPEG.SaveToStream(JPEGStream);

except

On E: Exception do

ShowMessage(E.Message);

end;

finally

JPEGStream.Free;

JPEGStream := nil;

end;

finally

JPEG.Free;

JPEG := nil;

end;

end;

end;



=============================================================



procedure TData. DataChange(Sender: TObject; Field: TField);

begin

GetImageFromDB(Data.gigs.FieldByName('poster'), Main.poster);

end;



=============================================================





procedure GetImageFromDB(dbfield:TField; Image:Timage);

var memStream: TMemoryStream;

JPEG: TJPEGImage;

begin

If not dbfield.IsNull then

begin

try

JPEG := TJPEGImage.Create;

memStream := TMemoryStream.Create;

TBlobField(dbfield).SaveToStream(memStream);

memStream.Seek(0,0);

JPEG.LoadFromStream(memStream);

Image.Picture.Assign(JPEG);

finally

JPEG.Free;

memStream.Free;

JPEG := nil;

memStream := nil;

end;

end else begin

Image.Picture.LoadFromFile(AppDir+'noimage.bmp');

end;

end;



=============================================================



PHP CODE THAT ASSIGNED AND SAVES IMAGES TO MYSQL TABLE



Insert the image into a MySQL table via PHP



<form method="post" action="insert.php" enctype="multipart/form-data">

<h1>Upload an Image File</h1>

<h3>Please fill in the details below to upload your file.

Fields shown in <font color="red">red</font> are mandatory.</h3>

<table>

<col span="1" align="right">



<tr>

<td><font color="red">Short description:</font></td>

<td><input type="text" name="short" size=50></t