Why does it only write the first line to the file???
Posted: Sat Jun 26, 2004 11:14 am
Ok guys got it to write to file but now it only writes one line of the file, the top line to the file.
The textarea is at the top of the screen and you are meant to be able to click on a file it opens in the textarea (editing), you then edit the file and resave it using the save field. However it only saves the first line of the file. The rest of the code works below is a copy of all the code. Bit messy but not bothered really cause it works.
feyd | swapped
Code: Select all
function writefile($editing){if(!empty($_POST['save'])){
$TheFile = 'form_data/'.$_POST['save'].'.txt';
$Open = @fopen($TheFile, 'w');
if($Open === FALSE){
} else {
fputs($Open, $editing);
fclose($Open);
}
}}
print("<table border=0 width=450 cellspacing=2 cellpadding=2 align=center>");
print("<TR><TD colspan=5>");
if($save){
$c1=writefile("$editing");
if($c1)
echo '<tr><td colspan="5" align"center">Error occured during processing please go back and retry.</td></tr>';
}else{
echo '<tr><td colspan="5" align"center">file created/updated.</td></tr>';}Code: Select all
if($edit){
for($n = 0; $n<count($edit); $n++){
print("<TR><TD colspan=5>The file currently being edited is:<B> form_data/$edit[$n]</B>");
}}else{
print("<TR><TD colspan=5>No file currently being edited");
}
print("<form action=files.php method=post enctype=multipart/form-data>\n");
print("<TR><TD colspan=5><textarea name="editing" cols=60 rows=10 NOWRAP>");
if($edit){
for($n = 0; $n<count($edit); $n++){
$TheFile = "form_data/$edit[$n]";
$Open = fopen ($TheFile, "r+");
if($Open){
$data = file($TheFile);
$getline = explode("\t",$data[$n]);
print("$getline[0]\t$getline[1]");
fclose($Open);
}else{
print("Unable to open a file<BR>\n");
}
}}
print("</TEXTAREA>
<TR><TD colspan=5>
<TR><TD colspan=5>Save As:<input type=text name="save" size=20>Code: Select all
<HTML><HEAD><TITLE>Moderators Page</TITLE></HEAD><BODY bgcolor=white>
<?
function writefile($editing){if(!empty($_POST['save'])){
$TheFile = 'form_data/'.$_POST['save'].'.txt';
$Open = @fopen($TheFile, 'w');
if($Open === FALSE){
} else {
fputs($Open, $editing);
fclose($Open);
}
}}
print("<table border=0 width=450 cellspacing=2 cellpadding=2 align=center>");
print("<TR><TD colspan=5>");
if($save){
$c1=writefile("$editing");
if($c1)
echo '<tr><td colspan="5" align"center">Error occured during processing please go back and retry.</td></tr>';
}else{
echo '<tr><td colspan="5" align"center">file created/updated.</td></tr>';}
if($Upload){
print("<TR><TD colspan=4><CENTER>Uploaded file name:$File_name</TD></TR>");
print("<TR><TD colspan=4><CENTER>Uploaded file size:$File_size</TD></TR>");
if(copy($File, "form_data/$File_name")){
print("<TR><TD colspan=4><CENTER>Your file, $File_name, was successfully uploaded!</TD></TR>");
}else{
print("<TR><TD colspan=4>Your file, $File_name, could not be copied.</TD></TR>");
}
unlink($File);
print("<TR><TD colspan=4><CENTER> <TD></TR>");
}
if($Rename){
for($n = 0;$n < count($Rename); $n++){
$OldFilename = $Rename[$n];
$Old = "form_data/$OldFilename";
$New = "moderated/$OldFilename";
if(rename("$Old", "$New")){
print("<TR><TD colspan=4><CENTER>Your file $Rename[$n], was successfully moved!</TD></TR>");
}else{
print("<TR><TD colspan=4><CENTER>Your file, $Rename[$n], could not be moved.</TD></TR>");
}
}
print("<TR><TD colspan=4><center> </TD></TR>");
}
if($Delete){
for($i = 0;$i < count($Delete); $i++){
if(unlink("form_data/$Delete[$i]")){
print("<TR><TD colspan=4><CENTER> Your file $Delete[$i], was successfully deleted!</TD></TR>");
}else{
print("<TR><TD colspan=4><CENTER>Your file, $Delete[$i], could not be deleted.</TD></TR>");
}
}
print("<TR><TD colspan=4><CENTER> </TD></TR>");
}
if($edit){
for($n = 0; $n<count($edit); $n++){
print("<TR><TD colspan=5>The file currently being edited is:<B> form_data/$edit[$n]</B>");
}}else{
print("<TR><TD colspan=5>No file currently being edited");
}
print("<form action=files.php method=post enctype=multipart/form-data>\n");
print("<TR><TD colspan=5><textarea name="editing" cols=60 rows=10 NOWRAP>");
if($edit){
for($n = 0; $n<count($edit); $n++){
$TheFile = "form_data/$edit[$n]";
$Open = fopen ($TheFile, "r+");
if($Open){
$data = file($TheFile);
$getline = explode("\t",$data[$n]);
print("$getline[0]\t$getline[1]");
fclose($Open);
}else{
print("Unable to open a file<BR>\n");
}
}}
print("</TEXTAREA>
<TR><TD colspan=5>
<TR><TD colspan=5>Save As:<input type=text name="save" size=20>
<TR><TD><B>File Name
<TD><B>File Size
<TD><B>Delete
<TD><B>Move to Moderated
<TD><B>Edit");
$open = opendir ("form_data");
while($Files = readdir($open)){
$Filename = "form_data/" . $Files;
if(is_file($Filename)){
$Size = filesize("form_data/$Files");
print("<TR><TD>$Files</TD>
<TD>$Size<TD><INPUT type=checkbox name="Delete[]" value=$Files>
<TD><Input type=checkbox name="Rename[]" value=$Files>
<TD><Input type=radio name=edit[] value=$Files>
");
}}
closedir($open);
print("<TR><TD colspan=4>
<TR><TD colspan=4 align=center><input type=checkbox name=Upload value=yes>Upload A File:<Input type=file name=File size=20></TD></TR>
<TR><TD colspan=4 align=center><input type=submit name=submit value=Submit!>
</TABLE>\n");
?>
</BODY></HTML>feyd | swapped
Code: Select all
forCode: Select all
tags.[/color]