我試圖將一個非常大的表單保存爲一個SQL數據庫作爲XML。 表單是從用戶上傳的XML文件創建的,因此表單的大小未知。除非用戶上傳超過832個元素的文件,否則一切都很好。表單生成的很好,但從表單到XML的輸出只是在第832個元素之後結束。
表單看起來像這樣。此代碼等同於XML文件中的一個元素。
<tr>
<td><input type="text" name="115panel" value="1"></td>
<td><input type="text" name="115loop" value="1"></td>
<td><input type="text" name="115zone" value="1"></td>
<td><input type="text" name="115det" value="5"></td>
<td><input type="text" name="115type" value="OPT"></td>
<td><input type="checkbox" name="115ir" value="1"></td>
<td><input type="checkbox" name="115ok" value="1"></td>
<td><input type="checkbox" name="115iok" value="1"></td>
<td><input type="checkbox" name="115fr" value="1"></td>
<td><input type="text" name="115value" value="39"></td>
</tr>
$ _POST [name]和$ _POST [type]在窗體的開頭設置。
PHP的代碼來解析形式爲XML看起來像這樣
if($_POST['type'] == "PBS") {
$xml = new DOMDocument("1.0");
$root = $xml->createElement("data");
$root->setAttribute('name', $_POST['name']);
$root->setAttribute('type', $_POST['type']);
$xml->appendChild($root);
$i = 0;
$iP = 1;
$iL = 1;
$iD = 1;
$run = 1;
while($run == 1) {
$search = $iP;
$search .= $iL;
$search .= $iD;
if(isset($_POST[$search.'det'])) {
$id = $xml->createElement("ID".$i);
$root->appendChild($id);
$central = $xml->createElement("panel");
$centralText = $xml>createTextNode($_POST[$search.'panel']);
$central->appendChild($centralText);
$loop = $xml->createElement("loop");
$loopText = $xml->createTextNode($_POST[$search.'loop']);
$loop->appendChild($loopText);
$zone = $xml->createElement("zone");
$zoneText = $xml->createTextNode($_POST[$search.'zone']);
$zone->appendChild($zoneText);
$logicnumber = $xml->createElement("det");
$logicnumberText = $xml->createTextNode($_POST[$search.'det']);
$logicnumber->appendChild($logicnumberText);
$type = $xml->createElement("type");
$typeText = $xml->createTextNode($_POST[$search.'type']);
$type->appendChild($typeText);
$ir = $xml->createElement("ir");
$irText = $xml->createTextNode(xIt($_POST[$search.'ir']));
$ir->appendChild($irText);
$ok = $xml->createElement("ok");
$okText = $xml->createTextNode(xIt($_POST[$search.'ok']));
$ok->appendChild($okText);
$iok = $xml->createElement("iok");
$iokText = $xml->createTextNode(xIt($_POST[$search.'iok']));
$iok->appendChild($iokText);
$fr = $xml->createElement("fr");
$frText = $xml->createTextNode(xIt($_POST[$search.'fr']));
$fr->appendChild($frText);
$value = $xml->createElement("value");
$valueText = $xml->createTextNode($_POST[$search.'value']);
$value->appendChild($valueText);
$id->appendChild($central);
$id->appendChild($loop);
$id->appendChild($zone);
$id->appendChild($logicnumber);
$id->appendChild($type);
$id->appendChild($ir);
$id->appendChild($ok);
$id->appendChild($iok);
$id->appendChild($fr);
$id->appendChild($value);
$i++;
}
$iD++;
if($iD >= 250){
$iD = 1;
$iL++;
}
if($iL >= 9){
$iL = 1;
$iP++;
}
if($iP >= 10){
$iP = 1;
$run = 0;
}
}
$xml->formatOutput = true;
$mysqli->query("INSERT INTO kl_sks (customerID, user, date, data, status)
VALUES ('".addslashes($_POST['name'])."', '".$_SESSION[sesUser]."', '".time()."', '".$xml->saveXML()."', '1')");
}
該代碼通過250 * 8 * 9次循環。在832
這裏總共有18000倍,但輸出停止短路到最後一個的輸出的一個例子。
<ID831>
<panel>1</panel>
<loop>1</loop>
<zone>42</zone>
<det>13</det>
<type>801PH</type>
<ir>0</ir>
<ok>0</ok>
<iok>0</iok>
<fr>0</fr>
<value>5</value>
</ID831>
<ID832>
<panel>1</panel>
<loop>1</loop>
<zone>42</zone>
<det>14</det>
<type>801PH</type>
<ir>0</ir>
<ok>0</ok>
<iok>0</iok>
<fr>0</fr>
<value>8</value>
</ID832>
<data>
這是一個XML文檔有1300元,所以468元丟失
這似乎是一個問題,關於在php.ini中php_value max_input_vars 5000
,至極我不能改變。所以問題是如何將一個元素中的所有值輕鬆地組合到一個$ _POST變量中?
可以在你的php.ini –
增加'max_execution_time'標誌的問題I'dont知道如果我能做到這一點。該服務器由one.com託管。 – XerXeX
你可以試試。我不熟悉one.com,所以我在這裏沒有任何幫助。 –