Autor Beitrag
mtin
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 177

Win XP SP2
BDS2006 Enterprise
BeitragVerfasst: Mi 01.03.06 17:58 
also, ich versuche ein Bild auf imagehigh.com hochzuladen...
wer das normal ausprobieren will, hier ein kompaktes formular:

imagehigh.com/iframe...pe=blank&size=30

der quelltext des Forms ist folgender:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
<form action="http://www.imagehigh.com/uploadgallery.php" method="post" enctype="multipart/form-data" target="_blank">
 
  <input type="hidden" name="MAX_FILE_SIZE" value="1048576">
  <input type="hidden" name="aff" value="">
  <input type="hidden" name="type" value="blank">
  <input type="file" class="textfield" name="fileupload[]" size="30" >
  
  <input type="submit" name="upload" value="host it!" class="textfield">
</form>


sobald man dann da auf Upload drückt, wird das bild hochgeladen und man bekommt eine HTML-Seite wo die links draufstehen...
Das habe ich so in Delphi umgesetzt:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
procedure UploadFile(Filename: string);
var
  Stream:       TIdMultiPartFormDataStream;
  StringStream: TStringStream;
begin
Stream := TIdMultiPartFormDataStream.Create;
StringStream := TStringStream.Create('');
try
  Stream.AddFormField('MAX_FILE_SIZE','1048576');
  Stream.AddFormField('aff','');
  Stream.AddFormField('type','blank');
  Stream.AddFile('fileupload[]',Filename, 'multipart/form-data');
  Form1.IdHTTP1.Post('http://www.imagehigh.com/uploadgallery.php', Stream, StringStream);
  sl := TStringList.Create;
  sl.add(StringStream.DataString);
finally
  Stream.Free;
  StringStream.Free;
end;
end;


allerdings will das einfach nicht funktionieren...ich bekomme den gleichen kopf und fuß der html datei wie beim upload über den browser, nur es stehen dazwischen keine Links!!
Das bild wurde aber hochgeladen, wie ich durch das OnWork der IdHTTP-Komponente herausgefunden hab...
was kann da nicht stimmen?
komisch ist der name des Files, dieses "fileupload[]"...warum sind da 2 eckige klammern?
DaRkFiRe
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 526

WinXP Home & Professional
C, C++, Delphi
BeitragVerfasst: Mi 01.03.06 18:16 
Laut HTML-Standard dürfen in namen keine eckigen Klammern vorkommen!

Ich dachte auch erst, dass es für Felder sei, aber Pustekuchen, das wird von manchen Servern nicht erkannt...

_________________
Lang ist der Weg durch Lehren - kurz und wirksam durch Beispiele! Seneca
mtin Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 177

Win XP SP2
BDS2006 Enterprise
BeitragVerfasst: Mi 01.03.06 18:21 
das steht aber so in dem html quelltext der Seite...
und das klappt ja auch wenn ich das mit dem browser mache!
nur mit meinem delphi-code will es irgendwie nicht :(

sicher das das an den klammern liegt?
ich denk nich das die das wegen meinem programm umändern^^
mtin Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 177

Win XP SP2
BDS2006 Enterprise
BeitragVerfasst: Do 02.03.06 19:05 
Hier ist nochmal ein Teil des upload-scripts, ich glaube dieser gesamte abschnitt wird übersprungen wenn ich das Bild mit meinem Programm hochlade...
das heißt dieses if( isset($_POST['upload']) ) wird warscheinlich FALSE zurückgeben...
weiß jemand ob ich das oder wie ich das angebe? muss ich irgendwo in meinem delphi-source noch 'upload' reinbringen? oder was bedeutet das?
Wäre für jede noch so kleine Hilfe dankbar :D

ausblenden volle Höhe 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:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
// UPLOAD    
if( isset($_POST['upload']) ){
  if($_FILES){
    $counter = 0;
    $uploaded_file = array();    

    
    $ups = 0; $fails = 0; $tots = 0;

    foreach($_FILES['fileupload']['name'] as $file_name){      

      if($file_name != '' ){
        if($_FILES['fileupload']['size'][$counter] > 0 ){
          if(in_array($_FILES['fileupload']['type'][$counter] ,$supported_files)) {
            $uploaded_file[] = $ftp->upload_file( $_FILES['fileupload']['tmp_name'][$counter], FTP_DIR_LOC, $_FILES['fileupload']['name'][$counter]);
            $ups++;
          }
          else if($_FILES['fileupload']['error'][$counter] == 4){
            $fail_msg .= "<li> '".$_FILES['fileupload']['name'][$counter]."' not Found !!";          
            $fails++;
          }
          else if($_FILES['fileupload']['error'][$counter] == 2 || $_FILES['fileupload']['error'][$counter] == 1){
            $fail_msg .= "<li> '".$_FILES['fileupload']['name'][$counter]."' is exceeds size limit !!";          
            $fails++;
          }
          else{
            $fail_msg .= "<li> '".$_FILES['fileupload']['name'][$counter]."' is not supported !!";          
            $fails++;
          }
        }
        else{          
          $fail_msg .= "<li> '".$_FILES['fileupload']['name'][$counter]."' not Found !!";          
          $fails++;          
        }
        $tots++;
      } // if 

      $counter++;
    } // foreach
  }

  $ups_msg = $ups ." of ".$tots. " Images uploaded Successfully ...";

hier steht ja "for each", könnte das fileupload[] dann vll ein Array sein?
habs jetzt auch schonmal mit fileupload[0] bzw. [1] als namen für das File probiert....bringt aber genausowenig ;)
DaRkFiRe
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 526

WinXP Home & Professional
C, C++, Delphi
BeitragVerfasst: Do 02.03.06 23:34 
So sieht das wohl aus. Schließlich haste nicht mal ein Feld, was upload heißt.
Obacht: PHP unterscheidet zwischen GROß und klein!!!


PS: Das mit den eckigen Klammern hab ich mal aufgeschnappt. Ich konnte mir allerdings sonst auch nicht vorstellen, wie man komfortabel Arrays an das PHP-Script übergeben könnte.

_________________
Lang ist der Weg durch Lehren - kurz und wirksam durch Beispiele! Seneca
Timi-loader
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 58

Win XP
Delphi 7 Personal
BeitragVerfasst: So 20.05.07 18:19 
ich habe versucht den code oben zu kopieren, allerdings meint delphi er kenne TIdMultiPartFormDataStream nicht, obwohl ich doch idhttp1 drinnen hab.
weiß einer wieso?

mfg
Timi-loader
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 58

Win XP
Delphi 7 Personal
BeitragVerfasst: So 20.05.07 18:25 
ok sry habs.

hatte nur uses IdMultipartFormData; vergessen

mfg