脚本标题过早结束:php-cgi和内部服务器错误

时间:2015-11-30 03:42:41

标签: php excel content-management-system

需要一些帮助:我尝试将一些Excel工作表导入我的网站,但页面继续加载,然后停止工作并显示内部服务器错误文本。错误日志显示由import.php引起的:脚本标头的过早结束:php-cgi,referer:... file_import.php。

以下是代码:

<? include("../include/begin.inc.php");?>
<?

function showerror()
{
  die("Error " . mysql_errno() . " : " . mysql_error());
}

function sava_data($array, $table){
$count = 0; 
$total = 0; 
foreach( $array as $tmp){
  if ($count <> 0){ 
    $date =  date("Y:m:d H:i:s"); 
    $sql = "INSERT INTO $table set ";

    $sql .= "detail = '{$tmp[2]}', shape = '{$tmp[3]}', qty = '{$tmp[4]}', price = '{$tmp[5]}', percent = '{$tmp[6]}', colour = '{$tmp[7]}', clarity = '{$tmp[8]}', prop = '{$tmp[9]}', polish = '{$tmp[10]}', smy = '{$tmp[11]}', diam = '{$tmp[12]}', t_dep = '{$tmp[13]}', `table` = '{$tmp[14]}', fl = '{$tmp[15]}', colour_shade = '{$tmp[16]}', cert = '{$tmp[17]}', cert_no = '{$tmp[18]}', per_kg = '{$tmp[19]}', selling_price = '{$tmp[20]}', status = 'new', create_date = '{$date}'";
    //echo $sql."<br>";
    //exit();
    if (!($result = @mysql_query($sql) or die("Error:" . mysql_error().$sql)))
      showerror();

    $total++;
   }
   $count++; 


}
return $total;  
}

function save_data2($array,$table){
$count = 0; 
$total = 0; 
foreach( $array as $tmp){
  if ($count <> 0){ 
    $date =  date("Y:m:d H:i:s"); 
    $sql = "INSERT INTO $table set ";

    $sql .= "detail = '{$tmp[2]}', shape = '{$tmp[3]}', qty = '{$tmp[4]}', price = '{$tmp[5]}', percent = '{$tmp[6]}', colour = '{$tmp[7]}', clarity = '{$tmp[8]}', prop = '{$tmp[9]}', polish = '{$tmp[10]}', smy = '{$tmp[11]}', diam = '{$tmp[12]}', t_dep = '{$tmp[13]}', `table` = '{$tmp[14]}', fl = '{$tmp[15]}', colour_shade = '{$tmp[16]}', cert = '{$tmp[17]}', cert_no = '{$tmp[18]}', per_kg = '{$tmp[19]}', selling_price = '{$tmp[20]}', status = 'new', create_date = '{$date}'";
    //echo $sql."<br>";
    //exit();
    if (!($result = @mysql_query($sql) or die("Error:" . mysql_error().$sql)))
      showerror();

    $total++;
   }
   $count++;
}
return $total;
}

function empty_data($table){
    if($table == "fancy_table"){
        $s3 = "select * from $table where file != ''";
        $r3 = mysql_query($s3);
        while($d3 = mysql_fetch_array($r3)){
            $del_lo_l="../../_files/fancy_product/".$d3['file'];
            if(file_exists($del_lo_l))
            {
                @unlink($del_lo_l);
            }
        }

    }
$s4 = "truncate table `$table`";
mysql_query($s4);
$s5 = "OPTIMIZE TABLE `$table`";
mysql_query($s5);
}

//error_reporting(E_ALL ^​​ E_NOTICE);
$action = $_REQUEST['action'];
if($_POST){
if($action == "empty"){
  empty_data("artwork");
}else if($action == "imported"){ 
  $Import_TmpFile = $_FILES['file']['tmp_name'];

  $data = new Spreadsheet_Excel_Reader(); 
  $data->setOutputEncoding('UTF-8');
  $data->read($Import_TmpFile);

  $total = 0;
  //for ($i = 4; $i <= $data->sheets[0]['numRows']; $i++) {
        for ($i = 4; $i <= 65536; $i++) {
    if ($data->sheets[0]['cells'][$i][2] <> ""){ 
      $sql = "INSERT INTO artwork set detail = '".$data->sheets[0]['cells'][$i][2]."', shape = '".$data->sheets[0]['cells'][$i][3]."', qty = '".$data->sheets[0]['cells'][$i][4]."', price = '".$data->sheets[0]['cells'][$i][5]."', percent = '".$data->sheets[0]['cells'][$i][6]."', colour = '".$data->sheets[0]['cells'][$i][7]."', clarity = '".$data->sheets[0]['cells'][$i][8]."', prop = '".$data->sheets[0]['cells'][$i][9]."', polish = '".$data->sheets[0]['cells'][$i][10]."', smy = '".$data->sheets[0]['cells'][$i][11]."', diam = '".$data->sheets[0]['cells'][$i][12]."', t_dep = '".$data->sheets[0]['cells'][$i][13]."', `table` = '".$data->sheets[0]['cells'][$i][14]."', fl = '".$data->sheets[0]['cells'][$i][15]."', colour_shade = '".$data->sheets[0]['cells'][$i][16]."', cert = '".$data->sheets[0]['cells'][$i][17]."', cert_no = '".$data->sheets[0]['cells'][$i][18]."', per_kg = '".$data->sheets[0]['cells'][$i][19]."', selling_price = '".$data->sheets[0]['cells'][$i][20]."', status = 'new', create_date = now()";
      $result = @mysql_query($sql);
      $total++;
    }
  }
  echo $total;
  //$total = sava_data($array, "artwork");
}else if($action == "fancy_imported"){ 
  $Import_TmpFile = $_FILES['file']['tmp_name'];
  $data = new Spreadsheet_Excel_Reader(); 
  $data->setOutputEncoding('UTF-8');
  $data->read($Import_TmpFile);
  $total = 0;
  //for ($i = 4; $i <= $data->sheets[0]['numRows']; $i++) {
        for ($i = 4; $i <= 65536; $i++) {
    if ($data->sheets[0]['cells'][$i][2] <> ""){ 
      $sql = "INSERT INTO fancy_style set detail = '".$data->sheets[0]['cells'][$i][2]."', artworktype = '".$data->sheets[0]['cells'][$i][3]."', shape = '".$data->sheets[0]['cells'][$i][4]."', qty = '".$data->sheets[0]['cells'][$i][5]."', colour = '".$data->sheets[0]['cells'][$i][6]."', cut = '".$data->sheets[0]['cells'][$i][7]."', measurements = '".$data->sheets[0]['cells'][$i][8]."', treatment = '".$data->sheets[0]['cells'][$i][9]."', origin = '".$data->sheets[0]['cells'][$i][10]."', comments = '".$data->sheets[0]['cells'][$i][11]."', cert = '".$data->sheets[0]['cells'][$i][12]."', cert_no = '".$data->sheets[0]['cells'][$i][13]."', `per_kg` = '".$data->sheets[0]['cells'][$i][14]."', status = 'new', create_date = now()";
      $result = @mysql_query($sql);
      $total++;
    }
  }
  echo $total;

}else if($action == "fancy_empty"){
  empty_data("fancy_style");
}
}  
//exit();
jsRedirect(geturlname().".php?action=".$action."&rows=".$total);

?>
<? include("../include/end.inc.php");?>

0 个答案:

没有答案