2015-12-02 87 views
0

我的頁面上有一個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: /

+0

錯誤發生之前你有什麼? –

+0

它工作正常,相同的腳本沒有變化。 –

+0

和你的ajax上傳代碼在哪裏?我們也會看到。 – Jai

回答

1

檢查你的web服務器錯誤日誌。取決於Web服務器,應位於/ var/log/apache或/ var/log/nginx中。

這些會給你提供有關實際發生錯誤的信息,你應該能夠從那裏輕鬆解決問題。

+0

我同意@rlweb,對於500錯誤代碼服務器錯誤日誌文件是最豐富的。 – Giuseppe

+0

apache2目錄爲空。 nginx的不存在 –

+0

在Plesk中能說會道下登錄它只是說,2015年12月2日9點36分20秒 錯誤 IP POST /upload.php HTTP/1.1 的Mozilla/5.0(Macintosh上,Intel處理器的Mac OS X 10_11_1)爲AppleWebKit/601.2.7(KHTML,例如Gecko)版本/ 9.0.1 Safari瀏覽器/ 601.2.7 Apache的SSL –