du20150401 2012-02-28 01:01
浏览 36
已采纳

PHP创建要发送的文件,输出缓冲区已经发送?

Hey I guys I wrote a function to force out a json file, but it seems that the buffer concatenating the file somehow. Normally it should just be a JSON object, but it looks like the page itself is being inserted into the file?

 [{"key":"16","role":null,"region":"Great White North","inspection_type":"citrus","inspection_number":"996","customer_number":"206-420-9564","report_date":"2012-10-21","status":"1","order_date":"2012-02-23 15:24:34","customer":"Jd Daniel","customer_division":"Field worker","memo":null,"billing_key":null,"report_key":"996","shipper":"Hanjin","po":"33215","location":"Boulder, CO","inspector":"Newman","commodity":"Apples","count":"32","size":"medium","label":"Granny Smith","variety":"Golden","pack_date":"0000-00-00","grower_lot":"Lots to grow","color1":"4","color2":"15","texture1":"","texture2":"","puff1":"","puff2":"","scar1":"","scar2":"","solidity1":"","solidity2":"","green1":"","green2":"","sugar_brix1":"","sugar_brix2":"","rating":"0","comments":"Comments 1"},{"key":"17","role":null,"region":"Great White North","inspection_type":"citrus","inspection_number":"996","customer_number":"206-420-9564","report_date":"2012-10-21","status":"0","order_date":"2012-02-23 15:24:34","customer":"Jd Daniel","customer_division":"Field worker","memo":null,"billing_key":null,"report_key":"996","shipper":"Jiun Ming","po":"4215","location":"South Holywood","inspector":"Gadget","commodity":"Grapes","count":"29","size":"46","label":"sweet","variety":"green","pack_date":"0000-00-00","grower_lot":"","color1":"","color2":"","texture1":"","texture2":"","puff1":"","puff2":"","scar1":"","scar2":"","solidity1":"","solidity2":"","green1":"","green2":"","sugar_brix1":"","sugar_brix2":"","rating":"0","comments":"Comments 2"}]
    <!DOCTYPE html>
    <html lang="en-US">
        <head>
         <title> </title>

         <script src='http://www.google.com/jsapi'></script>
         <script> google.load('jquery', '1.7.1'); </script>

        <style type="text/css">
        body {font-family: arial;}
         p, ul {width:100%; text-align:left;font-size:80%;}
         .reports_box {width:auto; padding:25px 20px 20px 20px;border:1px solid #91bce6;background-color:#eff5fb;}
         input {width:121px; font-size:15px;padding:5px;}
         .check input {padding:0 !important;}
         .caps {text-transform:capitalize;}

Weird right? I can't get the buffers to flush right to remove this and am hoping for a better way to get this working. Here's my function.

function getReportDown($array) {
unset($array['select']);

$cleanArray = filter_var_array($array ,FILTER_SANITIZE_STRING); 

$array=array(); // needs to be secured -jd
foreach($cleanArray as $k=>$v) {
  if(strpos($k,'find_') === false) { 
    $array[] = explode(':',$k); }
}

    require('perms.php.inc');
    require('dbconnect.class.inc');

    $dbc = Database::obtain(DB_HOST, DB_USER, DB_PASS, DB_NAME);
    $dbc->connect();

    $form=array();
    foreach($array as $key=>$val) {
        $form[] = array_pop($dbc->fetch_array("SELECT * FROM reports JOIN ( SELECT * FROM `{$val[0]}` WHERE `key` = {$val[1]}) fruits ON inspection_number = fruits.report_key ORDER BY report_date DESC"));
    }

    $dbc->close();

    $rand = randomAlphaNum(10).'.json';

    header("Content-type: application/json");
    header("Content-disposition: attachment; filename=$rand");
    header('Content-Transfer-Encoding: binary');
    echo json_encode($form);

    //unlink($rand);

}
  • 写回答

1条回答 默认 最新

  • dongwa3808 2012-02-28 01:03
    关注

    exit or die after you echo the JSON.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Stata链式中介效应代码修改
  • ¥15 latex投稿显示click download
  • ¥15 请问读取环境变量文件失败是什么原因?
  • ¥15 在若依框架下实现人脸识别
  • ¥15 添加组件无法加载页面,某块加载卡住
  • ¥15 网络科学导论,网络控制
  • ¥15 利用Sentinel-2和Landsat8做一个水库的长时序NDVI的对比,为什么Snetinel-2计算的结果最小值特别小,而Lansat8就很平均
  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错