简体   繁体   中英

Create PHP file using PHP

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"

在此处输入图片说明

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

在此处输入图片说明

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

在此处输入图片说明

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM