klaus: File-Upload mit AJAX und PHP

Beitrag lesen

Hallo alle zusammen,

stehe vor folgendem Problem: Ich muss über unser CMS eine Datei vom lokalen Host auf den Server hochladen. Jedoch läuft das CMS mit AJAX. Und da ist - soviel hab ich schon herausgefunden - ein File-Upload eine schwer lösbare Aufgabe.

Mein Aufruf sieht folgendermassen aus:

  
-- SNIP --  
<form action="PHP_SELF" enctype="multipart/form-data" method="post" name="upload_form">  
  <input type="hidden" name="MAX_FILE_SIZE" value="16000000">  
  Upload-File:<input name="xml_file" type="file" accept="text/xml">  
  <input type='button' onclick="document.upload_form.bereich_auswertung.value='...'; readSendForm(document.upload_form); return document.returnValue; this.form.submit()" style="background-image: url(/img/button_02.gif)">  
</form>  
-- SNAP --  

Und die dazugehörenden JavaScripts:

[code lang=javascript]
function readSendForm(pFormId)
{
 if(http_request==false)
 {
  //Formularinformationen
  var form = pFormId;
  var fAction = pFormId.action;
  var fMethod = pFormId.method;
  var fEnctype = pFormId.enctype;

// Belegung Standardwert:
  if(fEnctype == '') fEnctype = 'application/x-www-form-urlencoded';

errors = '1';
  info = '';
  makePOSTRequest(fAction, fMethod, info, fEnctype, readSendForm);
  document.returnValue = (errors == '');
 }
 else
 {
  if (http_request.readyState == 4)
  {
   if (http_request.status == 200)
   {
    result = http_request.responseText;
   }
   else
   {
    // Fehlermeldung
   }
   http_request=false;
  }
 }
}

function makePOSTRequest(pUrl, pMethod, pContent, pType, pFunction)
{
-- SNAP --
.
.
.
-- SNIP --
 if(pMethod=='Get' || pMethod=='GET' || pMethod=='gGet')
 {
  urlString = pUrl+'?'+pContent;
  http_request.open('GET', urlString, true);
  http_request.onreadystatechange = pFunction;
  http_request.send(null);
 }
 else
 {
  http_request.onreadystatechange = pFunction;
  http_request.open('POST', pUrl, true);
  http_request.setRequestHeader("Content-type", pType);
  http_request.setRequestHeader("Content-length", pContent.length);
  http_request.setRequestHeader("Connection", "close");
  http_request.send(pContent);
 }
}
[/code ]

Result gibt einen Wert zurück (nämlich genau den Quelltext der Page), $_FILES ist jedoch leer und die Auswertungsseite wird auch nicht aufgerufen. Es scheint, als wäre der 'this.form.submit()'-Aufruf komplett wirkungslos.

Was muss ich noch umsetzen, damit der Fileupload funktioniert?

LG Klaus