Form that creates new file on submit

I’m trying to make a php page that has a text field where any user can input something like “example.php” and click submit and have it create that page based off a template I already have. I also need the form to have 1 more additional variable in the form of another text field that replaces the text in the tag of the new page. can anyone please help me out?

Oh and here is the forum post i’ve been trying to follow but I got lost somewhere around posting the form and saving it as an array. ???:
http://www.webmasterworld.com/php/3552317.htm

here is my code:

[code]<?php

$tpl_file = “template.php”;
$tpl_path = “/”;
$members_path = “/”;

$data[‘filename’] = $_POST[‘filename’];
$data[‘ext’] = $_POST[‘ext’];
$data[‘doctitle’] = $_POST[‘doctitle’];
$placeholders = array("{filename}", “{ext}”, “{doctitle}”);

$tpl = file_get_contents($tpl_path.$tpl_file);
$new_member_file = str_replace($placeholders, $data, $tpl);

$html_file_name = $data[‘filename’].$data[‘ext’];

$fp = fopen($members_path.$html_file_name, “a”);
fwrite($fp, $new_member_file);
fclose($fp);

?>[/code]

HERES THE FORM:

[code]


File Name:




.html
.php
.js
.css


    Page Title:
    <label for="doctitle"></label>
    <input name="doctitle" type="text" id="doctitle" size="40" />
  </p></td>
<td width="223" align="center">
  <input type="submit" name="createpage" id="createpage" value="Create New Webpage" />
</form>[/code]

thanks in advance I’m a total newb at php so please take it easy.

Well, where to start… First, are you pulling the file from the user’s computer or from your server?

Your code has a file entry area which should add a browse button on the user’s page where they
can select a file. But, why all of the work can code to grab the ext? the extension is part of the
posted value array. But, it should work as-is. Next, you save the file in your root directory of the
server. This is NOT a good idea. Normally, you would save it into a folder and call the folder something
like “files” or “Uploads” or whatever.

Lastly, to display a file that has been saved to a website placing inside another webpage can be a bit
tricky. So, we understand why you might have issues with it. First, you can not place two headers on
any webpage. Therefore, you can NOT easily load a webpage into another one. One way around this
is to load the page into an iFrame. “iFrames” are not used much these days as they are considered
“non-standard” and can be hacked by loading a page into the iFrame with programming inside it.

Now, what you showed us was a small PHP code that pulls a file from a user’s input and saves it to your
server. And, another form that allows users to input a filename and some extension option which is not
needed. (You can grab the extention from the full filename that was posted.)

So, where is the page that displays the file that was uploaded? The first two parts kinda work, but, you
still need the part that displays the page. Also, you must remember that not all pages will be allowed to
be displayed.

I guess that we need to know a little more on what you are attempting to display. Does this template that
you already have created use iFrames or were you planning on displaying the data just inside a

tag?
Not really clear on what you are attempting to do…
Sponsor our Newsletter | Privacy Policy | Terms of Service