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
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)
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