
21.03.2006, 12:11
|
|
Познающий
Регистрация: 13.02.2006
Сообщений: 88
Провел на форуме: 304371
Репутация:
16
|
|
Код:
<?
$file_dir = "news";
$limit = 5;
function open_dir($file_dir,$entry1,$i){
global $entry1, $i;
$d = dir($file_dir);
$i=0;
while($entry=$d->read()) {
if (substr($entry,0,4)=="news") {
$entry1[$i]=$entry;
$i++;
}
}
$d->close();
}
if($_SERVER['REQUEST_METHOD'] == "POST"){
if(empty($_POST['news']) || empty($_POST['textnews'])){
header("Location: ".$_SERVER['PHP_SELF']);
}else{
$news=str_replace("\n"," ",$_POST['news']);
$news=str_replace("\r"," ",$news);
$news=stripslashes($news);
$textnews=str_replace("\n"," ",$_POST['textnews']);
$textnews=str_replace("\r"," ",$textnews);
$textnews=stripslashes($textnews);
$file = fopen("news/news.".time(), "w+");
$array = array(date('d.m.Y'), $news, $textnews);
$news_save = implode("\n", $array);
fputs($file, $news_save."\n");
fclose($file);
header("Location: ".$_SERVER['PHP_SELF']);
}
}
elseif(!empty($_GET['dele'])){
unlink($file_dir."/news.".$_GET['dele']);
header("Location: ".$_SERVER['PHP_SELF']);
}elseif(!empty($_GET['uid'])){
$data = file($file_dir."/news.".$_GET['uid']);
echo trim($data[0]).' <a href="'.$_SERVER['PHP_SELF'].'?dele='.$_GET['uid'].'">Видалити</a><br>';
echo '<a href="'.$_SERVER['PHP_SELF'].'?uid='.$_GET['uid'].'">'.trim($data[1]).'</a><br>';
echo trim($data[2]);
echo '<hr style="border: #000000 1px solid" noshade size="1">';
}
else{
open_dir($file_dir,$entry1,$i);
@rsort($entry1);
$count=$i;
$cnt=$count;
if (empty($_GET['start'])) $_GET['start']=0;
$_GET['start']=intval($_GET['start']);
if ($_GET['start']<0) $_GET['start']=0;
if ($count>$_GET['start']+$limit) $count=$_GET['start']+$limit;
for($i=$_GET['start'];$i<$count;$i++){
$data = file($file_dir."/".$entry1[$i]);
echo trim($data[0]).' <a href="'.$_SERVER['PHP_SELF'].'?dele='.substr($entry1[$i],5).'">Видалити</a><br>';
echo '<a href="'.$_SERVER['PHP_SELF'].'?uid='.substr($entry1[$i],5).'">'.trim($data[1]).'</a><br>';
echo substr(trim($data[2]),0,100);
echo '<hr style="border: #000000 1px solid" noshade size="1">';
}
echo "<div align=left class=text>";
if ($_GET['start']!=0)
echo '<a href="'.$_SERVER['PHP_SELF'].'?start='.($_GET['start']-$limit).'"><<</a> | ';
if ($cnt>$_GET['start']+$limit)
echo '<a href="'.$_SERVER['PHP_SELF'].'?start='.($_GET['start']+$limit).'">>></a>';
echo "</div>";
echo '<form action="'.$_SERVER['PHP_SELF'].'" method="post">
<input name="news" maxlength="50" type="text"><br />
<textarea name="textnews" rows=5 cols=20 wrap="virtual"></textarea><br />
<input type="submit" value="Додати">
</form>';
}
?>
не мучайся - думфю разберешся
Последний раз редактировалось ferryman; 21.03.2006 в 12:17..
|
|
|