As said in the comments, this is not a good idea for many reasons. I'll show some of them and in the end a little Proof of Concept about one way to do it properly and Frameworks that can help. If you still want to do it in this way, check this awnser.
Maintenence by the server owner
Creating one file per "thread" can make things really hard to be changed. If you have some error on thread creator code (or even want to change some visual, brand, add a new feature, etc) you would have to change every already generated file.
Security
One security flaw would be multiplied to N files, making a huge headache. In your example, if you write threadContent
without escaping, it will lead to XSS that should be searched and fixed on every already generated file.
Administration by users
To edit typos, or any other thing that the user that generates the file wants, he would have to have access to edit files on your server, or you would have to create a script to change directly the file contents, which is bad.
Search engine
Imagine how difficult would be to create a search engine on your site to find some thread by title, content, etc on all files.
Fun fact
If the StackOverflow site uses this method and each question file has ~10kb, it would have ~206GB only in question files to manage. You can see how many questions StackOverflow has here.
How it should be done?
There are many ways to do it, I'll show one very simple to explain and some frameworks that can help you.
The data can be stored on your database, like:
id |
user_id |
title |
content |
1 |
1 |
Example |
Lorem Ipsum ... |
And then create one file that works as a template to serve all your user-generated threads:
thread-template.php
<!DOCTYPE html>
<html>
<head>
<title><?php echo htmlspecialchars($post['title'], ENT_QUOTES, 'UTF-8'); ?></title>
</head>
<body>
<?php echo htmlspecialchars($post['content'], ENT_QUOTES, 'UTF-8'); ?>
</body>
</html>
Before rendering the template, you need to fetch the data from the database:
$stmt = $pdo->query("SELECT * FROM posts WHERE id = 1");
$post = $stmt->fetch();
require("thread-template.php");
Frameworks
Many frameworks can help you to do it easily, using the MVC method.
Model
The central component of the pattern. It is the application's dynamic
data structure, independent of the user interface. It directly
manages the data, logic and rules of the application.
View
Any representation of information such as a chart, diagram or table.
Multiple views of the same information are possible, such as a bar
chart for management and a tabular view for accountants.
Controller
Accepts input and converts it to commands for the model or view.
Laravel
Codeigniter
CakePHP