2

Yes, i want to create an .html or .php (whatever) document with some forms.

Example:

The user opens a page (preference: php) and see 1 form for website title and 1 button. Ok, he put the website title of your preference an click in the button. This page send the information contained in the form and create an html/php document with the title that user put in form.

This is not about to show some variables in html with "echo", is about to really create some new document.

Anyone?

2
  • 3
    php.net/file_put_contents Commented Feb 24, 2014 at 13:33
  • And where should it save? On the server itself? Commented Feb 24, 2014 at 14:05

4 Answers 4

3

This should do what you want:

$title = $_POST['title'];
$html = '<html>
    <head>
        <title>' . htmlspecialchars($title) . '</title>
    </head>
    <body>Some HTML</body>
</html>';
file_put_contents('/path/to/file.html', $html);

That will create a file for you with the title the user submitted (assuming you are submitting by POST).

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

4 Comments

I would add to this answer that OP should be aware of the destination folder permissions. stackoverflow.com/questions/20283626/…
Hurray for XSS vulnerabilities!
Hurray for uploading a backdoor
@Jack There are plenty of other questions on SO that cover XSS. No need for me to repeat. Though I have updated my answer to at least prevent the basics.
2

So your form will need to be something like

<form action="" method="post">
    <input type="text" name="pageTitle" id="pageTitle" />
    <input type="submit" name="formSubmit" value="Submit" />
</form>

Then you will need to following code to capture the value of the page title and create the html page

if($_POST['formSubmit']) {
    $newpage = '<html><head><title>' . $_POST['pageTitle'] . '</title></head><body><-- Whatever you want to put here --></body></html>';
    file_put_contents('newpage.html', $newpage );
}

Comments

0

Try this :

<?php

$title = htmlspecialchars($_POST['title']);
$content = "<html><head><title>$title</title></head><body>Your content here</body></html>";

file_put_contents('index.html', $content);

Comments

0

You would echo the contents as usual but you should send the following headers:

header('Content-Disposition: attachment; filename=file.html'); //or whatever name you like here
header('Content-Type: text/html'); //or text/php if the file is php

This will make the browser open a download dialoug for your file

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.