Welcome Guest, Not a member yet? Register   Sign In
Help creating text file on the fly
#1

[eluser]ZeroLag[/eluser]
I am having problems with a tab character being added to a text file that I create on the fly, and push out via initiating a file download in the browser. The string is XML, and since there is space being added at the beginning, it fails XML validation. I have just put in a test string for privacy purposes in my example below:

This is in my controller:
Code:
$qwc = array('qwcFileName'=>'Test.txt', 'qwcData'=>'Test');

$length = strlen($qwc['qwcData']);

header("Pragma:  public");
header("Expires:  0");
header("Cache-Control:  must-revalidate, pre-check=0");
header("Cache-Control:  private", false);
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"" . $qwc['qwcFileName'] . "\"");
header("Content-Transfer-Encoding:  binary");
header("Content-Length:  $length");

print $qwc['qwcData'];

Is always outputs with a tab character before the word test in my output file sent to the browser. Can anyone help me with this? It's driving me crazy.

Thanks,
Steve
#2

[eluser]_www_[/eluser]
Hello Steve,

I just tested your source. Copy & paste into a new controller and executed it.
I opened the resulting file in notepad.

The result : there is no space or tab in front of the data.

Of cause, this is a text file that contains no XML. But i guess you have replaced that for the posting.
#3

[eluser]ZeroLag[/eluser]
I put my code in a NEW controller, and it works fine with and without real XML. It seems to only happen in my production controller, where I have a bunch of other code. I'm not sure where to even start looking for the issue. I guess I could make a new controller for just this functionality, but I don't really want to.
#4

[eluser]_www_[/eluser]
Hello Steve,

if it doesn't make sense, that the source code creates the wrong tab or space, then maybe it's one of these "space/tab in between ?> and <?php errors?




Theme © iAndrew 2016 - Forum software by © MyBB