CODE
$Title = "";
$Date = "";
$Post = "";
$Number = $_POST['Number'];
$Filename = "Data/PostData/Posts.txt";
$Posts = file_get_contents( $Filename );
if( $Number < 1 || $Number > $Posts )
{
header( "Location: Manager.php?Mng=Posts&Act=Delete" );
end();
}
file_put_contents( $Filename, $Posts - 1 );
for( $I = $Number + 1; $I <= $Posts; $I++ )
{
$Filename = "Data/PostData/Titles/" . $I . ".txt";
$Title = file_get_contents( $Filename );
$Filename = "Data/PostData/Dates/" . $I . ".txt";
$Date = file_get_contents( $Filename );
$Filename = "Data/PostData/Posts/" . $I . ".txt";
$Post = file_get_contents( $Filename );
$Filename = "Data/PostData/Titles/" . $I - 1 . ".txt";
file_put_contents( $Filename, $Title );
$Filename = "Data/PostData/Dates/" . $I - 1 . ".txt";
file_put_contents( $Filename, $Date );
$Filename = "Data/PostData/Posts/" . $I - 1 . ".txt";
file_put_contents( $Filename, $Post );
}
$Filename = "Data/PostData/Titles/" . $Posts . ".txt";
unlink( $Filename );
$Filename = "Data/PostData/Dates/" . $Posts . ".txt";
unlink( $Filename );
$Filename = "Data/PostData/Posts/" . $Posts . ".txt";
unlink( $Filename );
header( "Location: Manager.php?Mng=Posts&Act=Delete" );
end();
Does this (hackish) code look sound to you? Guess again! As far as my logic says, this will take the next file's contents and stick them in the deleted post's file, continue with the rest of the files, and then delete the last file. But it doesn't... Instead, it just deletes the last file and sticks -1.txt with the next post's contents in the root directory.
Why?!P.S. Yeah, I know it's kind of an ugly system. I'm going to convert it all to serialized arrays soon. I might move to SQL but I don't know...
Oh, and don't worry, that's not the code in its entirety. (The rest is irrelevant.)