0

I am calling a PHP script to download a file by clicking on HTML anchor <a>. I place some debugging information in that script and want to print it out during that script execution. However, this does not get printed out.

Example: I have an HTML anchor such as:

<a href="PHP/fileDownload.php?upload_id=1"> ▼ </a>

In the fileDownload.php script I have:

<?php
include 'ChromePhp.php';
require_once 'mysqlConnect.php';

echo "test\n test\n test\n test\n test\n test\n test\n test\n test\n test";
...

After I click the link, no test string contained within echo statement is printed out.

Could anybody clarify this for me, please? Is there a way to make echo statement work in my situation?

18
  • 1
    Enable error reporting first. Add ini_set('display_errors',1); error_reporting(E_ALL); to the top of your script and refresh the page. Commented Oct 27, 2013 at 11:43
  • What headers do you send out? Commented Oct 27, 2013 at 11:47
  • @AmalMurali: I did include those two commands. I did page refresh, however no change. No error neither. What is important, that script later contains file download. The file gets downloaded, so the script gets executed. The problem is, that it wont print anything on the screen. Commented Oct 27, 2013 at 11:47
  • 1
    @Bunkai.Satori Open the downloaded file. Do you find the strings there? Commented Oct 27, 2013 at 11:48
  • Then its surely because of headers Commented Oct 27, 2013 at 11:48

1 Answer 1

1
header("Content-Disposition: attachment; filename=\"uploaded.pdf\"");

Its because the HTTP headers, which you are sending like above, are telling the browser to expect a file to be downloaded. They are not telling browser to expect HTML content (default). Therefore the content you are sending in an echo is not getting displayed.

Both won't work together correctly although I'm sure you can find any work around but the point is that you only need those echo's while debugging so you can disable the mentioned header call while debugging and once everything is set, enable that again so file can download.

Sign up to request clarification or add additional context in comments.

3 Comments

But then it should be contained in the file downloaded.
I'm sure it must be there then.
Yes, I can confirm, the test string was in the file downloaded. It was at the beginning of the file. This is interesting new info for me. Thanks +1.

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.