/    Sign up×
Community /Pin to ProfileBookmark

writing to html file

Is there any way to design a form to write to another html file on the same server to edit the html file? What I am wanting to do is to allow my friends and I to be able to add pictures and videos to a website through a form. I want to keep it as simple as possible.

thanks,
Jared

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NogDogNov 18.2006 — Sure there's a way. PHP has all sorts of [url=http://www.php.net/manual/en/ref.filesystem.php]filesystem functions[/url]. The question will be what features you need and what sort of security restrictions. (You really don't want it to be easy for someone else to hack your sites to bit through an unsecure site update form.)

You might want to check out the various script sites for a ready-made content management system (CMS) and see if there's one with the features you need and that seems to have reasonable security measures built in.
Copy linkTweet thisAlerts:
@so_is_thisNov 18.2006 — Here is a simplistic little example of updating an HTML page -- this one updates itself:
[code=php]<?php
$file = basename($_SERVER['PHP_SELF']);
if ($_SERVER['REQUEST_METHOD'] == 'POST'):
$append = html_entity_decode($_POST['append']);
$append = preg_replace('/<[^>]*>/', '', $append);
$append = htmlentities($append);
if(!empty($append)):
$lf = "n";
$str = file_get_contents($file);
$tag = html_entity_decode('&lt;!-- append here --&gt;');
$str = str_replace($tag, '<p>' .wordwrap($append, 70, '<br>'.$lf).
'</p>' .$lf.$lf. $tag, $str);
$fp = fopen($file, "w");
fwrite($fp, $str);
fclose($fp);
header("Location: {$file}#append");
exit;
endif;
endif;
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Append Page</title>
</head>

<body>
<!-- append here -->
<form id="append" method="POST" action="<?=$file?>#append">
<p><textarea name="append" rows="6" cols="40"></textarea></p>
<p><input type="submit" value="Append"></p>
</form>
</body>
</html>[/code]
×

Success!

Help @jared24 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...