At some point, "^M" got written to the end of every single script I have, so I wrote up a quick script to read the contents of the directory and, file-by-file, read in the contents, rtrim the ^M off the end of each line, and write it out.
Here's the code:
---------------------
if ($dir = @opendir("source_dir")
{
while (($file = readdir($dir)) !== false)
{
if (strstr($file, "php" or strstr($file, "bck")
{
$fp = fopen($file, "r"
while (!feof($fp))
{
$chunk = fgets($fp, 1024);
$chunk = rtrim($chunk)."\n";
$file_complete = $file_complete.$chunk;
}
$fp2 = fopen("dest_dir/".$file, "w"
fwrite ($fp2, $file_complete);
fclose($fp2);
fclose($fp);
}
else
{
continue;
}
}
closedir($dir);
}
-----------------------
Things appear to work fine when I run it. In the destination directory (luckily, I didn't have it output to the EXACTY same directory ), I have the exact same number of files with the exact same names as in the source directory, but with one small difference: they all have the exact same content, too.
For some reason, the contents of the first file processed by the script is what gets written out to each and every file processed after that, so they're all identical in essence. The thing that bugs me is that is actually names the files properly, so I know its advancing through all the loops properly, but I cant find out what causes it to use the same data over and over.
Any help is most appreciated.
Here's the code:
---------------------
if ($dir = @opendir("source_dir")
{
while (($file = readdir($dir)) !== false)
{
if (strstr($file, "php" or strstr($file, "bck")
{
$fp = fopen($file, "r"
while (!feof($fp))
{
$chunk = fgets($fp, 1024);
$chunk = rtrim($chunk)."\n";
$file_complete = $file_complete.$chunk;
}
$fp2 = fopen("dest_dir/".$file, "w"
fwrite ($fp2, $file_complete);
fclose($fp2);
fclose($fp);
}
else
{
continue;
}
}
closedir($dir);
}
-----------------------
Things appear to work fine when I run it. In the destination directory (luckily, I didn't have it output to the EXACTY same directory ), I have the exact same number of files with the exact same names as in the source directory, but with one small difference: they all have the exact same content, too.
For some reason, the contents of the first file processed by the script is what gets written out to each and every file processed after that, so they're all identical in essence. The thing that bugs me is that is actually names the files properly, so I know its advancing through all the loops properly, but I cant find out what causes it to use the same data over and over.
Any help is most appreciated.