I’m on a website project and administrators are able to create categories. When they do make them the name of the category is added to the database.
In the PHP file that processes the form used to create categories, I create a directory with the given name in the specific directory of my host, which at this time looks like:
exec('mkdir /homezx/user/website/categories/' . $_POST['name']);
It works fine, but now I’d like to copy a template from a resource folder to this new created directory (would be the index of it) and I know how to do it.
exec('cp .../templates/index.php /.../categories/' . $_POST['name'] . '/index.php');
The problem is I want to craft this template so it can fit the folder where it is placed.
In the template file, I’ve replace all the parts that will be different from one to one index with the string ‘%name%’.
What could be the best way to copy this file in a created folder, after having changed all the ‘%name%’ by a given name (e.g. in the title tag)?
is this what you’re trying to do? it will open your templace, replace %name% with the new name, create the directory, and the new file, write the edited template file and save it