hpvc Posted April 26, 2011 Share Posted April 26, 2011 Hi there, I'm new a this, please help me: I've a page in php, that's showing the content of a table, but i want to put a link on it, to save that content in html file to my local hard disk. Can anyone help me please? Thanks a lot. Quote Link to comment https://forums.phpfreaks.com/topic/234748-content-to-html-help-please/ Share on other sites More sharing options...
PHPSuperNewb Posted April 26, 2011 Share Posted April 26, 2011 you can try creating a file that contains the html with this: http://www.tizag.com/phpT/filecreate.php I'm not sure if this can be used to store it anywhere on someone's computer though... :S Quote Link to comment https://forums.phpfreaks.com/topic/234748-content-to-html-help-please/#findComment-1206349 Share on other sites More sharing options...
Muddy_Funster Posted April 26, 2011 Share Posted April 26, 2011 Why not just use your browser to save the page? Quote Link to comment https://forums.phpfreaks.com/topic/234748-content-to-html-help-please/#findComment-1206350 Share on other sites More sharing options...
saurabhx Posted April 26, 2011 Share Posted April 26, 2011 When the link to save the page is clicked, make the following code execute:- header('Content-Type: text/html'); header('Content-Disposition: attachment; filename=file.txt'); echo "Hello"; // Output the page contents you want the user to download here Note: header() will not work if you have already output html content in the page. So in your case, probably is is best to write the above code in a separate file and link to that file. Even if the code is in a separate file, the user will not be taken to that new file, instead he will stay in the current page and a download prompt will be shown Quote Link to comment https://forums.phpfreaks.com/topic/234748-content-to-html-help-please/#findComment-1206359 Share on other sites More sharing options...
PHPSuperNewb Posted April 26, 2011 Share Posted April 26, 2011 When the link to save the page is clicked, make the following code execute:- header('Content-Type: text/html'); header('Content-Disposition: attachment; filename=file.txt'); echo "Hello"; // Output the page contents you want the user to download here Note: header() will not work if you have already output html content in the page. So in your case, probably is is best to write the above code in a separate file and link to that file. Even if the code is in a separate file, the user will not be taken to that new file, instead he will stay in the current page and a download prompt will be shown I forgot about using headers, this is a great solution! 0.0 Quote Link to comment https://forums.phpfreaks.com/topic/234748-content-to-html-help-please/#findComment-1206361 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.