php - Readfile problem - file downloaded include the file path and i don't know how to remove
Get the solution ↓↓↓The following code is properly working, but there is a little problem: the first line of the file downloaded has the path of the file. Don't know why, here's the code:
function aprifile()
{
$url = './file/'.$_POST['seconda'];
echo $url;
header("Content-Type: application/octet-stream");
header("Content-Transfer-Encoding: Binary");
header("Content-disposition: attachment; filename=$_POST[seconda]");
readfile($url);
exit();
}
Answer
Solution:
echo $url;
is the culprit.
It's important to realise that anything you output from PHP becomes part of the response going back to the browser. You've told the browser that the response is to be treated as a downloadable file rather than a HTML page.
readFile
does the same thing asecho
, except from a file instead of a variable - it reads the content of the file and puts it in PHP's output buffer.
If you want to add something like that for debugging, you need to make it log to a file on the server, not echo it as part of the output.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: a non well formed numeric value encountered
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.