This problem has me baffled.
I have a form which outputs the lines of a txt file into a table creating links. for each link there is a radio button which sends exact line form the txt file to the action page when the button is pressed.
In the action page all I want to do is put all of the lines in an array, do a string compare to find the line to remove (which comes from the form) then rewrite all of the lines minus the one to remove, back to the text file.
this works fine if you take out a line at the start or the middle but as soon as you try to remove the last line it rewrites the txt file and adds a carriage return at the end. For no apparent reason. It does not get added in my code.
here is my action page.
Please help...
$removefile = $_REQUEST['file'];
$filename = "../newsletters.txt";
$arrFp = file($filename);
$numLines = count($arrFp);
if (is_writable($filename)){
if (!$handle = fopen($filename, "w" )) {
exit;
}
for($i=0; $i<$numLines; $i++)
{
if(!strstr($arrFp[$i],$removefile)){
if (filesize($textfile)>0){
$inputappend = "\n".$arrFp[$i];
fwrite($handle, $inputappend);
}
else{
fwrite($handle, $arrFp[$i]);
}
}
}
list($file, $linkname) = split(";", $removefile);
$file = "../uploads/".$file;
unlink( $file );
echo "<h3>Your file has been removed successfully</h3>
}
else {
echo "Problem opening file $textfile";
}
I know nothing except the fact of my ignorance -Socrates
I have a form which outputs the lines of a txt file into a table creating links. for each link there is a radio button which sends exact line form the txt file to the action page when the button is pressed.
In the action page all I want to do is put all of the lines in an array, do a string compare to find the line to remove (which comes from the form) then rewrite all of the lines minus the one to remove, back to the text file.
this works fine if you take out a line at the start or the middle but as soon as you try to remove the last line it rewrites the txt file and adds a carriage return at the end. For no apparent reason. It does not get added in my code.
here is my action page.
Please help...
$removefile = $_REQUEST['file'];
$filename = "../newsletters.txt";
$arrFp = file($filename);
$numLines = count($arrFp);
if (is_writable($filename)){
if (!$handle = fopen($filename, "w" )) {
exit;
}
for($i=0; $i<$numLines; $i++)
{
if(!strstr($arrFp[$i],$removefile)){
if (filesize($textfile)>0){
$inputappend = "\n".$arrFp[$i];
fwrite($handle, $inputappend);
}
else{
fwrite($handle, $arrFp[$i]);
}
}
}
list($file, $linkname) = split(";", $removefile);
$file = "../uploads/".$file;
unlink( $file );
echo "<h3>Your file has been removed successfully</h3>
}
else {
echo "Problem opening file $textfile";
}
I know nothing except the fact of my ignorance -Socrates