I am writing an HTML file with part of a page, to be used later by HTMLDocX
in generating a .docx
file % (see this question related).
To write ob_start
and ob_get_clean
use to put the content in a variable:
ob_start();
// parte da página aqui
$var = ob_get_clean();
And then with file_put_contents
saved to a file in a server directory:
file_put_contents('/pasta/arquivo'.$id.'.html', $var); // cria o arquivo com o id criado antes.
So, in the HTMLDocX template just get the file with file_get_contents
:
$html = file_get_contents('../../pasta/arquivo'.$id.'.html');
But every time I test this on localhost (I have not yet gone to the server), I have to change the directory permission on the nail (with chmod
and such). I know that there must be a way to make this permission permanent, I have not yet seen it ... but then I was thinking that there could be serious security risks, since I am giving write permission to a directory (777).
In short, the question is:
What are the risks involved in the recording process and subsequent access of a
.hmtl
file on an Apache server with PHP, and how to avoid them? Is there a best practice for this?
In case it would be better to just save the HTML in the database and then access it through the mySQL query (I do this to generate the pdf, but pro docx I found it simpler to just save the file and then access HTMLDocX ...) p>