0

I have a page that has a link to my day.php page. The link is <a href="day.php">this day</a> and it is supposed to create a text file with today's day of the week on it. For example, the text file would only have the word Monday on it, because I am asking this question on a Monday. Right now, it creates the text file and writes the day of the week properly. My problem is that it is surrounding the day of the week in HTML code.

Here is my day.php page code:

<!doctype html>
<html>
   <head>
     <meta charset="utf-8">
     <title>Untitled Document</title>
   </head>

<body>
  <?php
    header('Content-type: application/txt');
    header('Content-Disposition: attachment; filename="day.txt"');
    echo date("l");
    echo "\r\n";
  ?>
</body>
</html>

Here is what I get in my created text file, day.txt:

<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Untitled Document</title>
  </head>

<body>
  Monday
</body>
</html>

When all I want is Monday.

If anyone knows the solution to my problem that would be greatly appreciated. Thank you for any help.

2
  • 1
    If you would like to send headers, you need to move headers() functions above HTML code. Anyway, why don't you just remove all the HTML code? It is unnecessary. Commented Mar 3, 2014 at 20:29
  • Well, I am creating a form for a shopping cart. I am trying to make the form create a text file with the user's product data and then send that text file to my email. For example, if they ordered two apples and a banana, I would like the submitted form to email me a text file with two apples and a banana on the file. I want this so I will be able to see what the user ordered. Commented Mar 3, 2014 at 20:37

1 Answer 1

1

You have all that HTML in the php file, simply remove it

<?php
header('Content-type: application/txt');
header('Content-Disposition: attachment; filename="day.txt"');
echo date("l");
echo "\r\n";
?>
Sign up to request clarification or add additional context in comments.

1 Comment

That works! Thank you. I wonder why that would cause that in the first place.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.