Reputation: 2809
I am creating text file in php, file has created in correct format from local pc and if i am trying online then no line break is there and not displaying formated.
I am using this code.
header("Content-type: application/txt");
header("Content-Length: ". sizeof($content));
header("Content-Disposition: inline; filename=". $file);
print $content; die;
If anyone have solutions please share with me.
Thanks in advance.
Upvotes: 1
Views: 1569
Reputation: 557
Try this
$content = str_replace("\n\r","\n",$content);
$content = str_replace("\r","\n",$content);
header("Content-type: text/plain");
header("Content-Length: ". sizeof($content));
header("Content-Disposition: inline; filename=". $file);
print $content; die;
Upvotes: 1
Reputation: 317177
Try
header('Content-Type: text/plain');
readfile($file);
This should be sufficient to send the file as plaintext. If this doesnt work for you for some obscure reason, a last resort would be to wrap the content in <pre>
tags.
Upvotes: 1
Reputation: 20706
text/plain
Content-Length
, not Content-Lenght
, and normally PHP will send this for youdie
, better use exit
.The problem is probably because of the wrong MIME type - some browsers will ignore invalid content types and display it as HTML.
Upvotes: 1
Reputation: 11076
you have a typo:
header("Content-Length: ". sizeof($content));
also, you should use
header("Content-type: text/plain");
Upvotes: 6