我的頁面上有一個Ajax上傳器。它從昨天開始運行良好。 現在,我得到一個錯誤500。在控制檯,它說Ajax上傳錯誤500
Failed to load resource: the server responded with a status of 500 (Internal Server Error)
,指的是我上傳的腳本:
<?php
// A list of permitted file extensions
$allowed = array('html','htm');
function save_table_to_json ($in_file, $out_file) {
$html = file_get_contents($in_file);
file_put_contents($out_file, convert_table_to_json($html));
}
function convert_table_to_json ($html) {
$document = new DOMDocument();
$document->loadHTML($html);
$xpath = new DomXPath($document);
$tables = $xpath->query("//*[contains(@class, 'mon_list')]");
$tableDom = new DomDocument();
$tableDom->appendChild($tableDom->importNode($tables->item(0), true));
$obj = [];
$jsonObj = [];
$th = $tableDom->getElementsByTagName('th');
$td = $tableDom->getElementsByTagName('td');
$thNum = $th->length;
$arrLength = $td->length;
$rowIx = 0;
for ($i = 0 ; $i < $arrLength ; $i++){
$head = $th->item($i%$thNum)->textContent;
$content = $td->item($i)->textContent;
$obj[ $head ] = $content;
if(($i+1) % $thNum === 0){
$jsonObj[++$rowIx] = $obj;
$obj = [];
}
}
return json_encode([ "Values" => $jsonObj ]);
}
if(isset($_FILES['upl']) && $_FILES['upl']['error'] == 0){
$extension = pathinfo($_FILES['upl']['name'], PATHINFO_EXTENSION);
if(!in_array(strtolower($extension), $allowed)){
echo '{"status":"error1"}';
exit;
}
if(move_uploaded_file($_FILES['upl']['tmp_name'], $_FILES['upl']['name'])){
save_table_to_json('heute_S.htm', 'heute_S.json');
save_table_to_json('heute_L.htm', 'heute_L.json');
save_table_to_json('morgen_S.htm', 'morgen_S.json');
save_table_to_json('morgen_L.htm', 'morgen_L.json');
echo '{"status":"success1"}';
}else{
echo '{"status":"error"}';
exit;
}
}
我didn't改變服務器中的任何。在服務器合法只說有錯誤500.
但我該如何解決?
編輯:
在登錄它說:
[Wed Dec 02 17:31:26.625826 2015] [fcgid:warn] [pid 11680] [client IP] mod_fcgid: stderr: PHP Warning: DOMDocument::loadHTML(): Empty string supplied as input in /upload.php on line 12, referer: /
第二:
[Wed Dec 02 17:31:26.625830 2015] [fcgid:warn] [pid 11680] [client IP] mod_fcgid: stderr: PHP Catchable fatal error: Argument 1 passed to DOMDocument::importNode() must be an instance of DOMNode, null given, called in /upload.php on line 7 and defined in /upload.php on line 17, referer: /
錯誤發生之前你有什麼? –
它工作正常,相同的腳本沒有變化。 –
和你的ajax上傳代碼在哪裏?我們也會看到。 – Jai