PHP: Why is this forced mime download adding 2 extra empty lines?

霸气de小男生 提交于 2019-12-02 06:21:27

As the php code itself looks ok and does not produce that new lines, this can have only one reason. You have a closing ?> tag and extra new lines at the end of your file:

?>
<--- empty line
<--- empty line

Note the content outside the php tags will not be parsed by PHP and just forwarded to the browser.

Solution: remove the closing ?> tag or the extra new lines. I usually prefer just not using the ?>


Btw, I should mention that this:

$fp = fopen($tab_del_file, "r");
fpassthru($fp);
fclose($fp);

can be simplified by

readfile($tab_del_file);

You most likely have an extra blank line after the closing ?>, which is being echoed with the data. The closing ?> is always optional at the end of a PHP file. Leaving it out is a good practice to prevent this sort of problem.

Actually this is problem due to position of php closing Tag.. ?>.

Basically the PHP closing tag on a PHP document ?> is optional to the PHP parser. So if it is used in your script and you leave any whitespace after ?> then it can cause unwanted error or output. I believe In your case also you would have done the same mistake.

So for this reason, PHP script should OMIT the closing Tag and instead you should use a comment block to mark the end of script.

Here is small example:

INCORRECT:

<?php

echo "Hello World!";

?>

CORRECT:

<?php

echo "Hello World!";

/* End of file myfile.php */
/* Location: ./system/modules/mymodule/myfile.php */ 

I Hope this helps you..!!

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!