3

I want to display an HTML page at a later date from the database by the user just having to enter the ID of the page.

Is there a better way to do this than just saving it as text in the database?

Thanks!

Hass
  • 1,628
  • 1
  • 18
  • 31

2 Answers2

3

Storing huge chunks of text (especially markup) in a DB tends to come with a host of annoying problems. I would instead just store the name of the file in the database and store the actual file on the filesystem.

Explosion Pills
  • 188,624
  • 52
  • 326
  • 405
  • Thank you for the quick response. So I should use a buffer? Like this http://stackoverflow.com/questions/3775281/save-current-page-as-html-to-server ? – Hass Nov 29 '12 at 03:04
  • @sas1ni69 that question doesn't make sense if we're talking about storage. – Explosion Pills Nov 29 '12 at 03:23
1

You could store the actual useful information from the file in the database. Like the title of the page and the content for each section of the page, and then render it using a template from on the disk somewhere. This means you can abstract all the information that is the same from every HTML file and save disk space too. (Its a small bonus though, it might be simpler to do as the other answer suggested and just save the file name in the database and have the file on the filesystem.) Having the information in the database itself might mean it will get backed up with the database, which might be useful to you. Who knows...

Something like flatpages from the django framework. https://docs.djangoproject.com/en/dev/ref/contrib/flatpages/?from=olddocs