Click here to Skip to main content
15,899,026 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I just want to write string in a file and let the user to download the file.
But when i write file its also write the other text from my html file.

My source code is this:

HTML
<html>
<head>
<title>File checking</title>
</head>
<body>
Hello how are you...
<div>
<?php
$string = "Hey i am just testing";

header('Content-Disposition: attachment; filename="sample.html"');
header('Content-Type: text/html');
header('Content-Length: ' . strlen($string));
header('Connection: close');


echo $string;
?>
</div>
</body>
</html>


And its out put is:
"Hello how are you...
Hey i am just testing"
Posted
Comments
Alamgirable 8-Feb-14 7:34am    
I only want to write "Hey i am just testing" but it also write "Hello how are you..." from my file as you can see

1 solution

This is because you are serving the file content within the html file. If you want the file content alone you will have to remove all html stuff around.
Alternatively you can provide a link to a standalone php script which will serve the file content.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900