2015-12-02 123 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 –