Jump to content

question regarding file output


heartburn

Recommended Posts

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:[code]<?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);
}

?>[/code]

index.php[code]<?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;

?>[/code]

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?

Link to comment
Share on other sites

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

[code=php:0]
<?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;

?>
[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.