Ajax を使用してファイルをアップロードしようとしていますが、ファイルの処理に問題があります... テスト目的で、次のような単純なコードを作成しました。
JS:
xmlhttp=new XMLHttpRequest();
xmlhttp.open("POST",document.getElementById('upload').action,true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
var cmdStr="q="+str;
xmlhttp.send(cmdStr);
document.getElementById("ResponseDiv").innerHTML=xmlhttp.responseText;
PHP:
$q=$_POST["q"];
echo $q;
正常に動作し、xmlhttp.responseText
印刷され[object File]
ます。
ただし、私の問題は、一時ファイル名を .xml で取得する必要があることです$_FILES["q"]['tmp_name']
。そのために、コードを次のように変更しました。
JS:
xmlhttp=new XMLHttpRequest();
xmlhttp.open("POST",document.getElementById('upload').action,true);
xmlhttp.setRequestHeader("enctype","multipart/form-data");
var cmdStr="q="+str;
xmlhttp.send(cmdStr);
document.getElementById("ResponseDiv").innerHTML=xmlhttp.responseText;
PHP:
$q=$_FILES["q"]["tmp_name"];
echo $q;
問題は、今ではxmlhttp.responseText
何も得られないことです。誰が私が間違っているのか知っていますか?