// _spoccon ist eine globale Variable - der Verbindungsdescriptor
function Tform1.append_satz (dateiname :
string) : boolean;
var img_pfad, thumb_pfad, dateibody, bildnr, extension :
string;
stmp :
string;
query : pchar;
datei : pchar;
img :
string;
thumb :
string;
img_fs : tfilestream;
img_sstream : Tstringstream;
thumb_fs : Tfilestream;
thumb_sstream : Tstringstream;
errorcode : integer;
begin
datei := Strlower(pchar(dateiname));
dateiname := AnsiToUtf8(datei);
img_pfad := label1.caption + '
\'+ dateiname;
thumb_pfad := label2.caption + '
\'+ dateiname;
img_fs := TFilestream.Create(img_pfad, fmopenread);
img_sstream := Tstringstream.Create('
');
try
img_fs.position := 0;
img_sStream.CopyFrom(img_fs,img_fs.size);
img_sStream.Position := 0;
img := escapestring(img_ssTream.DataString);
finally
freeandnil(img_fs);
freeandnil(img_sStream);
end;
thumb_fs := TFilestream.Create(thumb_pfad, fmopenread);
thumb_sstream := Tstringstream.Create('
');
try
thumb_fs.position := 0;
thumb_sStream.CopyFrom(thumb_fs,thumb_fs.size);
thumb_sStream.Position := 0;
thumb := escapestring(thumb_ssTream.DataString);
finally
freeandnil(thumb_fs);
freeandnil(thumb_sStream);
end;
extension := ExtractFileExt(dateiname);
dateibody := stringreplace(dateiname, extension, '
', [rfReplaceALL]);
bildnr := StringReplace(dateibody, '
img_', '
', [rfReplaceALL]);
stmp := '
INSERT INTO BILDER (img_nr, thumb, bild, galerie, fsk) VALUES (';
stmp := stmp + '
"' + thumb + '
", ';
stmp := stmp + '
"' + img + '
", ';
stmp := stmp + '
"' + bildnr + '
", ';
stmp := stmp + '
"01", ';
stmp := stmp + '
"J")';
query := PCHAR(stmp);
errorcode := mysql_real_query(_spoccon,
query, Length(
query));
stmp := mysql_error(_spoccon);
// showmessage(stmp);
end;
function Tform1.escapestring(
{const} str:
String):
String;
var i: integer;
tgt:
string;
begin
SetLength(tgt, Length(str) * 4);
try
i := mysql_real_escape_string(_spoccon, pchar(tgt), pchar(str), Length(str));
except
on E:
Exception do
showmessage('
Fehler: '+e.
message);
end;
result := tgt;
end;