I'm trying to open a file, overwrite one line, and then save the file to another directory. Everything works great - except that for some reason this script inserts my changes above the original text line, rather than replacing it. What am I doing wrong?
<?php
$tutorialText = fopen ("./$directory/$current_tutorial.txt", "r");
while ($data = fgets($tutorialText, 4096))
{
$current_line++;
if ($current_line == $arrayPosition)
{
$contents .= $changedLine;
}
else {
$contents .= $data;
}
}
fclose($tutorialText);
$tutorialText = fopen("./$directory/pending/$current_tutorial.txt", "w");
fputs($tutorialText, $contents);
fclose($tutorialText);
?>