I need a good way to automatically rename some text files. I'm in the process of making a content management system for a friend. Currently I'm using the best I can come up with. I realize this code is HORRIBLY inefficient, but at the moment I'm just working with functionality. There are 8 news articles. Each one is stored in a text file. Each article has an accompanying title and image, in its own text file. This script is supposed to shift them down. For example, if I were to post a new article, I was article 7 to become article 8 to make room for the new item. I want the titles and images to shift as well. However, it is not working. Does anyone know why? Or even better, could someone direct me to a renaming script?
$filename1 = 'news1.txt';
$filename2 = 'news2.txt';
$filename3 = 'news3.txt';
$filename4 = 'news4.txt';
$filename5 = 'news5.txt';
$filename6 = 'news6.txt';
$filename7 = 'news7.txt';
$filename8 = 'news8.txt';
$filename1b = 'news1title.txt';
$filename2b = 'news2title.txt';
$filename3b = 'news3title.txt';
$filename4b = 'news4title.txt';
$filename5b = 'news5title.txt';
$filename6b = 'news6title.txt';
$filename7b = 'news7title.txt';
$filename8b = 'news8title.txt';
$filename1c = 'news1image.txt';
$filename2c = 'news2image.txt';
$filename3c = 'news3image.txt';
$filename4c = 'news4image.txt';
$filename5c = 'news5image.txt';
$filename6c = 'news6image.txt';
$filename7c = 'news7image.txt';
$filename8c = 'news8image.txt';
$fp1 = fopen($filename1,"a+");
$fp2 = fopen($filename2,"a+");
$fp3 = fopen($filename3,"a+");
$fp4 = fopen($filename4,"a+");
$fp5 = fopen($filename5,"a+");
$fp6 = fopen($filename6,"a+");
$fp7 = fopen($filename7,"a+");
$fp8 = fopen($filename8,"a+");
$fp1b = fopen($filename1b,"a+");
$fp2b = fopen($filename2b,"a+");
$fp3b = fopen($filename3b,"a+");
$fp4b = fopen($filename4b,"a+");
$fp5b = fopen($filename5b,"a+");
$fp6b = fopen($filename6b,"a+");
$fp7b = fopen($filename7b,"a+");
$fp8b = fopen($filename8b,"a+");
$fp1c = fopen($filename1c,"a+");
$fp2c = fopen($filename2c,"a+");
$fp3c = fopen($filename3c,"a+");
$fp4c = fopen($filename4c,"a+");
$fp5c = fopen($filename5c,"a+");
$fp6c = fopen($filename6c,"a+");
$fp7c = fopen($filename7c,"a+");
$fp8c = fopen($filename8c,"a+");
$contents1 = fread($fp1, filesize($filename1));
$contents2 = fread($fp2, filesize($filename2));
$contents3 = fread($fp3, filesize($filename3));
$contents4 = fread($fp4, filesize($filename4));
$contents5 = fread($fp5, filesize($filename5));
$contents6 = fread($fp6, filesize($filename6));
$contents7 = fread($fp7, filesize($filename7));
$contents8 = fread($fp8, filesize($filename8));
$title1 = fread($fp1b, filesize($filename1b));
$title2 = fread($fp2b, filesize($filename2b));
$title3 = fread($fp3b, filesize($filename3b));
$title4 = fread($fp4b, filesize($filename4b));
$title5 = fread($fp5b, filesize($filename5b));
$title6 = fread($fp6b, filesize($filename6b));
$title7 = fread($fp7b, filesize($filename7b));
$title8 = fread($fp8b, filesize($filename8b));
$image1 = fread($fp1c, filesize($filename1c));
$image2 = fread($fp2c, filesize($filename2c));
$image3 = fread($fp3c, filesize($filename3c));
$image4 = fread($fp4c, filesize($filename4c));
$image5 = fread($fp5c, filesize($filename5c));
$image6 = fread($fp6c, filesize($filename6c));
$image7 = fread($fp7c, filesize($filename7c));
$image8 = fread($fp8c, filesize($filename8c));
fwrite($fp8, $contents7);
fwrite($fp7, $contents6);
fwrite($fp6, $contents5);
fwrite($fp5, $contents4);
fwrite($fp4, $contents3);
fwrite($fp3, $contents2);
fwrite($fp2, $contents1);
fwrite($fp8b, $contents7);
fwrite($fp7b, $contents6);
fwrite($fp6b, $contents5);
fwrite($fp5b, $contents4);
fwrite($fp4b, $contents3);
fwrite($fp3b, $contents2);
fwrite($fp2b, $contents1);
fwrite($fp8c, $contents7);
fwrite($fp7c, $contents6);
fwrite($fp6c, $contents5);
fwrite($fp5c, $contents4);
fwrite($fp4c, $contents3);
fwrite($fp3c, $contents2);
fwrite($fp2c, $contents1);
fclose($fp1);
fclose($fp2);
fclose($fp3);
fclose($fp4);
fclose($fp5);
fclose($fp6);
fclose($fp7);
fclose($fp8);
fclose($fp1b);
fclose($fp2b);
fclose($fp3b);
fclose($fp4b);
fclose($fp5b);
fclose($fp6b);
fclose($fp7b);
fclose($fp8b);
fclose($fp1c);
fclose($fp2c);
fclose($fp3c);
fclose($fp4c);
fclose($fp5c);
fclose($fp6c);
fclose($fp7c);
fclose($fp8c);