Jump to content


Photo

question regarding file output


  • Please log in to reply
2 replies to this topic

#1 heartburn

heartburn
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 10 October 2006 - 09:46 PM

I have a few files that do the following:

1. This one generates an xml file based on the time.
2. This file should (in theory) access the first file and get the output of the first file.

What is actually happening is that the second file is accessing the first file and spitting out all of the code that I have (for the first file).

I know that most people would like to see code rather than just hear me talk so here we go:

timeTest.php:
<?php

error_reporting(0);

//  This top area sets the current time, gets the date and names the xml doc
$date = date("m/d/Y");
$fileDate = date("mdy");
$time = date("H:i:s");
$xmlFileName = "$fileDate.xml";
$default = "default.xml";

//  This next area will find and open the xml file
if (file_exists($xmlFileName)){
    $xml = simplexml_load_file($xmlFileName);
    trim($xml);
    countNow($xml, $time, $date);
    } else {
	// if the file for today's date is not found, this file will play
    $xmlFileName = $default;
    $xml = simplexml_load_file($xmlFileName);
    trim($xml);
    countNow($xml, $time, $date);
}

//  This function counts the number of elements in the playlist
//  when it has that number it moves onto timeNow
function countNow($xml, $time, $date){
    $totalThread=0;
    foreach($xml->song as $num){
        $totalThread++;
    }
    timeNow($time, $xml, $date, $totalThread);
}

//  This function will take the time and finds where to start in the playlist
//  Once it has that it moves onto makeXML
function timeNow($time, $xml, $date, $totalThread){
    $threadNum = 0;
    do{
        $threadNum++;
    }while($time>$xml->song[$threadNum]['fileTime']);
    makeXML($time, $xml, $date, $totalThread, $threadNum);
}

//  This function will create an xml file for the playlist
//  Once it writes the first few lines it goes to getList for the bulk of the playlist
function makeXML($time, $xml, $date, $totalThread, $threadNum){
    echo "THIS WOULD HOUSE THE XML HEADER BUT IT WAS SCREWING UP THE CODE TAGS IN THE FORUM";
    echo "<playlist date=\"$date\">\n";
    echo "<song fileDate=\"$date\" fileTime=\"$time\" fileTitle=\"e360live.com Legal ID\" fileArtist=\"e360live.com\" fileSource=\"400000.flv\" nonmusic=\"Y\" fileLabel=\"\" />\n";
    getList($time, $xml, $date, $totalThread, $threadNum);
    echo "</playlist>";
}

//  This function populates the xml list with data from the called xml file
//  Once it is done, it goes back to makeXML for the closing of the xml file
function getList($time, $xml, $date, $totalThread, $threadNum){
    // This part checks to see if the first file is the 400000.flv, if so it skips it
    if($xml->song[$threadNum]['fileSource']=='400000.flv'){
        $threadNum++;
    }
    do{
    echo "<song fileDate=\"$date\" fileTime=\"".$xml->song[$threadNum]['fileTime']."\" fileTitle=\"".$xml->song[$threadNum]['fileTitle']."\" fileArtist=\"".$xml->song[$threadNum]['fileArtist']."\" fileSource=\"".$xml->song[$threadNum]['fileSource']."\" nonmusic=\"".$xml->song[$threadNum]['nonmusic']."\" fileLabel=\"".$xml->song[$threadNum]['fileLabel']."\" />\n";
    $threadNum++;
    }while($threadNum<$totalThread);
}

?>

index.php
<?php

error_reporting(0);

$info = file_get_contents("timeTest.php");

$ctype="application/octet-stream";

// disable HTML page caching on the PHP session level
session_cache_limiter("nocache");
header("Expires: 0");
// HTTP/1.1
// disable browser and proxy cache
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
// HTTP/1.0
header("Content-Type: $ctype");
header("Pragma: ");

echo $info;

?>

Alright, so you see the code, but when I run the second one (index.php) instead of printing the output of the file I get the code from timeTest.php (the first file).

I take it that I am using the wrong function (file_get_contents)...  is there a way to get the xml output instead?



#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 10 October 2006 - 10:44 PM

You would want to wrap a call to include within output buffering. Something like....

<?php

error_reporting(0);

ob_start();
include("timeTest.php");
$info = ob_get_contents();
ob_end_clean();

$ctype="application/octet-stream";

// disable HTML page caching on the PHP session level
session_cache_limiter("nocache");
header("Expires: 0");
// HTTP/1.1
// disable browser and proxy cache
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
// HTTP/1.0
header("Content-Type: $ctype");
header("Pragma: ");

echo $info;

?>


#3 heartburn

heartburn
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 11 October 2006 - 12:16 AM

That's great, I will try it in the morning.  Thanks for the reply.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users