/    Sign up×
Community /Pin to ProfileBookmark

Blog Script Help

<?php

$tt = $_POST[“title”];
$mm = $_
POST[“main”];

$contadd = (‘<!– start of entry –><h3>’.$tt.'</h3><p class=”p-Rightside” width=”100%”>’.$mm.'</p><!– end of entry –>’);
$one = fopen(‘blog/it.txt’, ‘r+’);
$contents = fread($one, filesize(‘blog/it.txt’));
$contents = $contadd.$contents;
fwrite($one, $contents, strlen($contents));
fclose($one);

echo ($contents);

?>

^ i use that for a blog script, it seems to somehow dupliocate whats already there or something… anything wrong? i want it to open and copy, add one to the beginning, and close.

see it in use at cammo91.ifreepages.com/gggraphix/index.php
add at cammo91.ifreepages.com/gggraphix/writeitform.html << if that dosent work look at:
cammo91.ifreepages.com/gggraphix/

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@ShrineDesignsSep 21.2004 — try this:[code=php]<?php
$file = 'blog/it.txt';

if($_POST)
{
$contents = "";

if(file_exists($file))
{
$fp = fopen($file, 'rb');
$contents = fread($fp, filesize($file));
fclose($fp);
}
$prepend = "<!-- start of entry -->
<h3>{$_POST['title']}</h3>
<p class="p-Rightside">{$_POST['main']}</p>
<!-- end of entry -->
";
$fp = fopen($file, 'wb');
fwrite($fp, $prepend.$contents);
fclose($fp);
}
echo file_get_contents($file);
?>[/code]
×

Success!

Help @CammoDude91 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.15,
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,
)...