简体   繁体   中英

PHP: echo not working from within <a href=“”> links

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM