Autor Beitrag
Florian H
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 52

Win XP
D6 Pro
BeitragVerfasst: Mo 09.08.04 13:44 
Hi,

wie kann ich denn in Delphi+PHP eine Bild-Datei (JPG) hochladen?

Die suche hier und in anderen Foren liefert ein paar brauchbare Ergebnisse, leider funzt das alles nicht, ich bekomme immer die Meldung "Connection closed gracefully" und nix is auf dem server. Hilft auch nix wenn ich das PHP-Script tausche oder den Server wechsle. PHP-Version > 4.0 und Delphi-Version 6 Pro.
Aktuelle INDYs.

Delphi-Code
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
procedure TForm1.sendfile(filename:string);
var
  data: TIdMultiPartFormDataStream;
begin
  data := TIdMultiPartFormDataStream.Create;
  try
    data.AddFile('bilddatei', filename, 'image/jpeg');
    data.Position := 0;
    Memo1.Lines.Text := IdHTTP1.Post('http://xyz.de/upload.php', data);
  finally
    data.Free;
  end;
end;


PHP-Code [oder auch der aus dem PHP-Manual)
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
<?php
$extlimit = "yes"; //Do you want to limit the extensions of files uploaded
$limitedext = array(".gif",".jpg",".png",".jpeg"); //Extensions you want files uploaded limited to.
$sizelimit = "yes"; //Do you want a size limit, yes or no?
$sizebytes = "100000"; //size limit in bytes
if($bilddatei!= "")
{
if (($sizelimit == "yes") && ($bilddatei_size > $sizebytes))
{
echo "Die Bilddateiname ist zu gross, sie darf mamimal $sizebytes bytes sein.";
}
$ext = strrchr($bilddatei_name,'.');
if (($extlimit == "yes") && (!in_array($ext,$limitedext)))
{
echo "Die Bilddateiname hat nicht die richtige Endung.";
}
elseif (file_exists("images/$bilddatei_name"))
 {
echo "Die Bilddateiname existiert bereit. Bitte ändere deine Bilddateiname und versuche es nochmal.";
}
else
{
copy($bilddatei,"images/$bilddatei_name");
}
}
?>


Woran könnte es liegen!? Gibts vielleicht ein Set aus Delphi-und PHP-Code das auf jeden fall funktioniert?

FTP is nix weil nicht jeder die Daten aussniffen können soll.

Grüße
Florian
maxk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1696
Erhaltene Danke: 1

Win XP, Debian Lenny
Delphi 6 Personal
BeitragVerfasst: Mo 09.08.04 13:46 
Connection Closes Gracefully hört sich sehr nach Delphi an. Allerdings ist diese Meldung nicht immer ein schlechtes Zeichen. Wird die Datei denn hochgeladen? Ansonsten mal mit F7 bzw. F8 debuggen und schauen, wo der Fehler auftritt.

_________________
Ein Computer wird das tun, was Du programmierst - nicht das, was Du willst.
Florian H Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 52

Win XP
D6 Pro
BeitragVerfasst: Mo 09.08.04 17:14 
Hi,
ja, der Fehler kommt von Delphi.

Die Datei wird nicht hochgeladen, der Fehler tritt bei idHTTP1.Post(...) auf.

gruß
flo
Florian H Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 52

Win XP
D6 Pro
BeitragVerfasst: Mo 09.08.04 17:39 
ok jetzt habe ich es geschafft, dass die Meldung vom PHP-Script kommt...
Zitat:

<pre>Possible file upload attack! Here's some debugging info:
Array
(
)


:cry: