0

What I currently have...

I have an ADD RECORD page where I add new partner stores that I work with. After I fill out the fields and click Save, it saves the data to a MYSQL table.

My Goal...

I would like a new PHP file get created in my web directory (root is fine) using the contents of one of the fields on the ADD RECORD page. Additionally, I would like that file that gets created have preset content.


Here is an example: (with screenshots)

1) I'll create a new record. The 4th field called EDIT URL will be the input field I would like to use for the file name creation. Let's say I give it the name "edit_paint_store"

enter image description here

2) After click SAVE RECORD, a new file will be created in my web dir called "edit_paint_store.php"

enter image description here

3) Not only will it create the file with this name, but it will always include a template code I will use.

enter image description here

Hopefully this explains well enough and will be happy to provide any further details.

6
  • 4
    Please, do not do that. It's very inconvenient template system. Imagine you want to change anything in your template. Add, remove, update anything in your template will be very painful. Try to create common template system and one point of entry. Commented Jun 7, 2016 at 5:57
  • +1 sectus. In your edit_paint_store there should only be one line. include 'template.php' and then you edit the template if anything needs to change Commented Jun 7, 2016 at 6:10
  • 1
    PHP was essentially created so that you do not have to do stuff like this. PHP is really good at generating content on-the-fly, and you should look into doing that. Commented Jun 7, 2016 at 6:16
  • Just imagine if you have 3000 stores and files, if you want update a section! how you will update those 3000 files? Commented Jun 7, 2016 at 6:51
  • I just realized my error. That I should just use variables in an EDIT.PHP file. Thanks for all the valuable input. Commented Jun 7, 2016 at 6:52

2 Answers 2

1

You can do it like this: Create a php page like as dynamic.php:

<form name="form1" action="" method="post">
Edit Url:
<input type="text" name="url" />
<input type="submit" name="submit1" value="generate" />
</form>

<?php
if(isset($_POST["submit1"])){
include "sms.php";
 $filename = $_POST["url"];
 $file = $filename.".php"; 
 header("Cache-Control: public");
 header("Content-Description: File Transfer");
 header("Content-Disposition: attachment; filename=$file");
 header("Content-Type: application/octet-stream; ");
 header("Content-Transfer-Encoding: binary");
}
?>

Here in the "template.php", you can specify your default template and the name you enter in the textbox that name file will be created containing the default template.

Sign up to request clarification or add additional context in comments.

Comments

0

I will suggest you use .htaccess rules for this purpose.

Just create a php file all-stores.php and show all store here.

Add a url_key field in table and put unique key for each store.

In all-store.php show that url_key in hyper link like

<a href="<?php echo $url_key.".php"; ?>">Store Name</a>

And then in your .htaccess file just add this rule.

RewriteRule ^/([a-zA-Z0-9%.\-_]+)\.php?$ /store_detail.php?url_key=$1 [QSA,L]

In store_detail.php get this url_key using $_GET['url_key']; and get store detail from database using this url_key.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.