【发布时间】:2015-12-02 08:39:51
【问题描述】:
我的页面上有一个 Ajax 上传器。从昨天开始它工作得很好。 现在我收到错误 500。在控制台中显示
加载资源失败:服务器响应状态为 500(内部服务器错误)
并引用我的上传脚本:
<?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;
}
}
我没有更改服务器上的任何内容。在服务器合法只说有一个错误 500。
但是我该如何解决呢?
编辑:
在日志中显示:
[2015 年 12 月 2 日星期三 17:31:26.625826] [fcgid:warn] [pid 11680] [客户端 IP] mod_fcgid:stderr:PHP 警告:DOMDocument::loadHTML():空字符串 在第 12 行的 /upload.php 中作为输入提供,引用者:/
第二个:
[2015 年 12 月 2 日星期三 17:31:26.625830] [fcgid:warn] [pid 11680] [客户端 IP] mod_fcgid: stderr: PHP Catchable fatal error: 参数 1 传递给 DOMDocument::importNode() 必须是 DOMNode 的实例,给定 null, 在第 7 行的 /upload.php 中调用并在第 17 行的 /upload.php 中定义, 推荐人:/
【问题讨论】:
-
出现错误之前你有什么?
-
它在相同的脚本下运行良好,没有任何变化。
-
您的 ajax 上传代码在哪里?我们也会看到的。
-
这些是我使用模板的代码。迈诺特熟悉 Ajax。
-
错误500是由服务器引起的,而不是客户端引起的。您必须共享您的服务器代码,而不是 javascript。您必须检查 apache 服务器中的错误日志,然后您就会知道会自动发生什么
标签: javascript php jquery ajax