Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 4 years ago.
Improve this questionI have tried some things... But can't download a txt file without getting all html code. I have a <a href='download/?cpf=1231231&nome=YanF'>Download</a>
to link do the code that will do all download code.
Here what I have so far:
<?php
ob_clean();
if(isset($_GET['cpf'])){
//config
$namefile = $_GET['nome'].'.txt';
$content = $_GET['cpf'];
//save file
$file = fopen($namefile, "w") or die("Unable to open file!");
fwrite($file, $content);
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.basename($namefile).'"');
header('Expires: 0');
header('Pragma: public');
header('Content-Length: '. filesize($file));
// ob_clean();
flush();
readfile($file);
}
ob_clean();
?>
EDIT --- I DID IT !!
After trying some more I changed what I was doing.
I created a template and a blank page, in that template I do what is above and redirect my <a>
to that page. And works... Don't know if there's other way but that's what I could do to make work like I want.
Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 4 years ago.
Improve this questionI have tried some things... But can't download a txt file without getting all html code. I have a <a href='download/?cpf=1231231&nome=YanF'>Download</a>
to link do the code that will do all download code.
Here what I have so far:
<?php
ob_clean();
if(isset($_GET['cpf'])){
//config
$namefile = $_GET['nome'].'.txt';
$content = $_GET['cpf'];
//save file
$file = fopen($namefile, "w") or die("Unable to open file!");
fwrite($file, $content);
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.basename($namefile).'"');
header('Expires: 0');
header('Pragma: public');
header('Content-Length: '. filesize($file));
// ob_clean();
flush();
readfile($file);
}
ob_clean();
?>
EDIT --- I DID IT !!
After trying some more I changed what I was doing.
I created a template and a blank page, in that template I do what is above and redirect my <a>
to that page. And works... Don't know if there's other way but that's what I could do to make work like I want.
1 Answer
Reset to default 2Try : header('Content-Type: text/plain');