I'm trying to create a blank html file through php. I wrote some code but it seems not to be working. This is my code:
$filename = 'test.html';
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=$filename");
header("Content-Type: application/octet-stream; ");
header("Content-Transfer-Encoding: binary");
When I click the link that would create this file, it gives me an html file but when I see the source it shows the source code of the page where i requested this.
Is there any reason why this wont work? Also, what is faster? To generate an html file everytime a user asks or to just pull a created empty file and just rename it when the user asks? Thanks!
You may want to use the fopen function:
$file = fopen("test.html", 'w') or die("can't open file");
fclose($file);
This should create a file named test.html in the same path as the .php file that executed the code
For those that stumbled on this question like I did for creating a fully empty file in PHP, a very short solution is doing the following:
file_put_contents('test.html', '');
To which you can simply link them to that file, to answer OP's question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With