Php Wordpress添加文件导入-无法修改标题信息-标题已发送

Php Wordpress添加文件导入-无法修改标题信息-标题已发送,php,html,wordpress,session,Php,Html,Wordpress,Session,我正在自定义wordpress页面以添加导入csv文件功能。我遇到了“无法修改标题信息-标题已发送”错误。不知道我哪里做错了,也不知道我怎么能检查这个 这是我试图自定义的php模板文件。 wordpress中有几个部分是必需的。但它似乎并不是问题的根源,因为在我删除这些部分后,它仍然收到错误消息 <?php /* Template Name: csvImportTmp*/ ?> <?php session_start(); //get_header(); ?>

我正在自定义wordpress页面以添加导入csv文件功能。我遇到了“无法修改标题信息-标题已发送”错误。不知道我哪里做错了,也不知道我怎么能检查这个

这是我试图自定义的php模板文件。 wordpress中有几个部分是必需的。但它似乎并不是问题的根源,因为在我删除这些部分后,它仍然收到错误消息

<?php /* Template Name: csvImportTmp*/ ?>

<?php 
session_start();
//get_header(); 
?>


<?php
/*This part is for importing csv button*/
//error checking
ini_set('display_errors', 1);
error_reporting(E_ALL);



$connect = mysqli_connect("localhost","username","password","db_name"); //initiate connection 
if(isset($_POST["submit"])) //if submit button is pressed 
{
  if($_FILES['file']['name']) //if file exists
  {
    $filename=explode('.', $_FILES['file']['name']);//seperate file into filename and csv
    if($filename[1]=='csv'){  //if file format is csv
      $handle= fopen($_FILES['file']['tmp_name'], "r");
      while($data=fgetcsv($handle)){
        $sql="INSERT INTO val_in (xxx,xxx,xxx,xxx,xxx,xxx) VALUES(?,?,?,?,?,?)";
        //prepared statement 
        $stmt=mysqli_stmt_init($connect);
        if(!mysqli_stmt_prepare($stmt,$sql)){
          // echo "SQL prepared statement error";
        }
        else{
          mysqli_stmt_bind_param($stmt,"ssssss",$data[0],$data[1],$data[2],$data[3],$data[4],$data[5]);
          mysqli_stmt_execute($stmt);
        }
        mysqli_query($connect,$sql);
      }
      fclose($handle);
        //print "import done";
    }
  }
  header("Location: http://localhost:8888/xxx/wordpress/xxx/?file=test.csv&submit=Import");
  return;
}

?>

  <div id="primary" class="content-area">
    <main id="main" class="site-main" role="main">

      <?php
      while ( have_posts() ) : the_post();

        get_template_part( 'template-parts/content', 'page' );

        // If comments are open or we have at least one comment, load up the comment template.
        if ( comments_open() || get_comments_number() ) :
          comments_template();
        endif;

      endwhile; // End of the loop.
      ?>

    </main><!-- #main -->
  </div><!-- #primary -->

  <p id="genValRes"><span id="genValRes"></p>
  <p id="clearValIn"><span id="clearValIn"></p>

  <div>
    <button id='genRes' onclick="genValRes();" name="genRes" class="button">Generate Result</button> 
    <button id='genRes' onclick="clearValIn();" name="genRes" class="button">Clear Input Table</button>  

  </div>


  <div>
    <form method='POST' enctype='multipart/form-data'>

       <div align="center">  
          <label>Import CSV File:</label>
          <input type="file" name="file" />
          <br />
          <input type="submit" name="submit" value="Import" class="btn btn-info" />
         </div>


    </form>  
  </div>

<?php
news_portal_get_sidebar();
get_footer();

产生结果 清除输入表 导入CSV文件:
ob_start()放入wp config.php

标题(“位置:http://localhost:8888/xxx/wordpress/xxx/?file=test.csv&submit=Import");:此行应引发错误。加载模板时,如果已经发送了标题,请尝试钩住一些操作,这些操作会在前面从
functions.php
文件或其他地方触发