Writing the output of a function to another file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shara
    New Member
    • Dec 2006
    • 28

    #1

    Writing the output of a function to another file

    Hello there,

    I used 'header' function to call a php page.The output of this page should be sent to a different directory as a file in the directory.

    My code is like this
    header('locatio n:full_report_e xporting.php?te st_runid='.$tes t_runids[$i][0]);

    Now full_report_exp orting.php generates a xls file which i have to store in a directory(name-xls files).

    I'm quite new to php and dont know in depth.Can anybody help me with how to achieve this.

    Thanks in advance,
    Shara.
  • satya61229
    New Member
    • Feb 2007
    • 24

    #2
    Originally posted by shara
    Hello there,

    I used 'header' function to call a php page.The output of this page should be sent to a different directory as a file in the directory.

    My code is like this
    header('locatio n:full_report_e xporting.php?te st_runid='.$tes t_runids[$i][0]);

    Now full_report_exp orting.php generates a xls file which i have to store in a directory(name-xls files).

    I'm quite new to php and dont know in depth.Can anybody help me with how to achieve this.

    Thanks in advance,
    Shara.
    I did not get the problem. But here
    header('locatio n:full_report_e xporting.php?te st_ru nid='.$test_run ids[$i][0]);
    you have space between test_ru and nid. is it ok?
    and try using
    error_reporting (E_ALL); at top of each page.

    Comment

    • shara
      New Member
      • Dec 2006
      • 28

      #3
      Originally posted by satya61229
      I did not get the problem. But here
      header('locatio n:full_report_e xporting.php?te st_ru nid='.$test_run ids[$i][0]);
      you have space between test_ru and nid. is it ok?
      and try using
      error_reporting (E_ALL); at top of each page.
      Hello Satya,

      That additional space is not there in actual script.It is given here by mistake.

      My problem is that full_report_exp orting.php generates an xls file taking test_runid as input.Now i want to direct the generated xls file into a directory as a file,say some_file_name. xls.

      I also used
      shell_exec("/www/ngnsite/D/FSD_ENS_RnD_TTS/project_report/full_report_exp orting.php?test _runid=".$test_ runids[$i][0]." > directory_name/file_name");

      But i'm not getting the file into the directory.Can you please help me out.Thanks for responding.

      Thanks&Regards,
      Shara.

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        The problem probably lies in the 'full_report_ex porting.php'scr ipt. So show the code of that script here. ANd do not forget to show that code within PHP or code tags!!!

        Ronald :cool:

        Comment

        • shara
          New Member
          • Dec 2006
          • 28

          #5
          Originally posted by ronverdonk
          The problem probably lies in the 'full_report_ex porting.php'scr ipt. So show the code of that script here. ANd do not forget to show that code within PHP or code tags!!!

          Ronald :cool:
          Hello Ronald,

          full_report_exp orting.php is working well coz the else part of the below given code is showing the output perfect.

          <?php
          ob_start();
          session_registe r("SESSION");

          require_once("W orksheet.php");
          require_once("W orkbook.php");
          require("../include/smcconf.php");
          require("../include/smclib.php");

          $smc = new SMC;
          $smc->connect("$SMCU SER@$SMCSERVER" , "$SMCPASSWD ") or die("Can not connect to database!");

          function HeaderingExcel( $filename)
          {
          header("Content-type: application/vnd.ms-excel");
          header("Content-Disposition: attachment; filename=$filen ame" );
          header("Expires : 0");
          header("Cache-Control: must-revalidate, post-check=0,pre-check=0");
          header("Pragma: public");
          }

          if(isset($test_ runid))
          {
          $test_run_name= "";
          $projectid=$SES SION["projectid"];
          $test_runid=$_G ET['$test_runid'];
          $sql = "select test_run_name
          from test_run
          where test_runid = (".$test_runid. ")";
          $smc->query($sql) or die("<h4>Error in selecting feature<br><br> ".$sql."</h4>");
          $test_run_name= $smc->result;
          $project_name=$ SESSION["project_na me"];
          }
          else
          {
          $projectid=$SES SION["projectid"];
          $test_runid=$SE SSION["test_runid "];
          $project_name=$ SESSION["project_na me"];
          $test_run_name= $SESSION["test_run_n ame"];
          }

          $filename = "full_report_". $project_name." _".$test_run_na me;
          $filename = str_replace('.' , '_', $filename);
          $filename = str_replace('/', '_', $filename);
          HeaderingExcel( $filename.".xls ");

          $workbook = new Spreadsheet_Exc el_Writer_Workb ook("-");

          $worksheet1 =& $workbook->addWorksheet(" Test List");
          $worksheet1->setColumn(1, 35, 5);

          $worksheet2 =& $workbook->addWorksheet(" FAILED TESTS");
          $worksheet2->setColumn(1, 25, 5);

          $worksheet3 =& $workbook->addWorksheet(" DDTS REPORT");
          $worksheet3->setColumn(1, 25, 5);

          $worksheet4 =& $workbook->addWorksheet(" Test Tracking Chart");
          $worksheet4->setColumn(0, 0, 25);
          $worksheet4->setColumn(1, 100, 6);

          $worksheet5 =& $workbook->addWorksheet(" Test Statistics");
          $worksheet5->setColumn(1, 25, 5);

          ?>

          The whole code is very big stretching to 2000 lines.I think the above part of code is sufficient to find if a problem is existing coz i'm using the variable passed in shell_exec command only in the above part.

          Thanks for acknowledging my mail.i will be grateful if you can guide me out through this.

          Thanks&Regards,
          Shara.

          Comment

          Working...