Alrite, I have a script that will write things to a file for a small, very basic guestbook. But, they add the new entries to the bottom of the list and I want them added to the top. What do I have to put into the write command that makes the script add the new entry to the top of the file?http://www.snippetlibrary.com/viewhtml.php?id=6&kid=14&siteid=234Thanks..but I've added that code and changed the things i needed to..but it still doesnt write to the top of the file. Here's what I'm workin with:
switch ($option2)
{
case 'sign':
echo("<center>Thanks for signing my guest book! You can now view it in my profile!</center>");
$file_name = "$dir/$sn/gbook.txt";
$fp=fopen("$file_name", "a+");
flock($fp, 2);
$old_data = fread($fp, ($file_name));
rewind($fp);
fwrite($fp, "<a href=http://www.htmlforums.com/archive/index.php/\"aim:goim?ScreenName=$who\">$who</a>: $gbook<br>\n" . $old_data);
flock($fp,3);
fclose($fp);
break;
default:
$who = str_replace("_", " ", "$who");
echo("Sign $sn's Profile Guestbook\n");
echo("<form name=\"book\">\n");
echo("<input type=hidden name=\"option2\" value=\"sign\">\n");
echo("<input type=hidden name=\"sn\" value=\"$sn\">\n");
echo("Screen Name:<input type=\"text\" name=\"who\" value=\"$who\"><br>");
echo("Message:<textarea name=\"gbook\" wrap=\"physical\" rows=\"5\" cols=\"39\"></textarea><br>");
echo("<input type=\"submit\" value=\"Sign It\"></center>");
echo("</form>");
break;
So could someone please tell me what I have wrong?instead of a+ use r+well now for some reason it's not rewriting the old data. When someone tries to add something its just overwrites all the old stuff with the new stuff. Any thoughts?alrite..so now i do have a question i dont know the answer to. When someone signs the guestbook that i have successfully created (thanks for the help ) it makes a gbook.txt file in the user's folder. But now say i need to delete a user..like one i just wanted to test scripts on, when i go to delete the files in my FTP client, it tells me that i dont have permission to delete them. So how do i go in and delete these files and folders. Any thoughts?ok try this
$oldmask = umask(0);
$file_name = "$dir/$sn/gbook.txt";
$fp=fopen("$file_name", "a+");
flock($fp, 2);
$old_data = fread($fp, ($file_name));
rewind($fp);
fwrite($fp, "<a href=http://www.htmlforums.com/archive/index.php/\"aim:goim?ScreenName=$who\">$who</a>: $gbook<br>\n" . $old_data);
flock($fp,3);
fclose($fp);
chmod($file_name, 0777);
umask($oldmask);
don't ask but it just works. um..yeah..it didnt work. So any other ideas? Like is there a script i can use that you enter the file and the path and it just deletes the file? Mad confused, any thoughts?umm yeah did you get an error?
try this way
$oldmask = umask(0);
$file_name = "$dir/$sn/gbook.txt";
$fp=fopen("$file_name", "a+");
flock($fp, 2);
$old_data = fread($fp, ($file_name));
rewind($fp);
fwrite($fp, "<a href=http://www.htmlforums.com/archive/index.php/\"aim:goim?ScreenName=$who\">$who</a>: $gbook<br>\n" . $old_data);
flock($fp,3);
fclose($fp);
exec(chmod $file_name 0777);
umask($oldmask);
if you want to delete a file you use unlink(file_name) and if you want to delete a folder you use rmdir($dir);
but you have to have the folder empty first.when i add that the gbook.php?sn=whatever page comes up blank..well i figured out that the problem occurs with the
exec(chmod $file_name 0777);
line but i dunno how to fix it.well i changed that line to
chmod ("$file_name", 0777);
but i still can't delete the file in my FTP client. Is this something im still doing wrong or should i contact the people who provide my server and ask for help?Just chmod the file to 777 in your FTP client and delete.
Good luck,
Paulwhen i try and chmodd it it says "550 gbook.txt: Operation Not Permitted"and when i try and delete it it says "550 gbook.txt: Permission Denied"that is why I said to do this
$oldmask = umask(0);
$file_name = "$dir/$sn/gbook.txt";
$fp=fopen("$file_name", "a+");
flock($fp, 2);
$old_data = fread($fp, ($file_name));
rewind($fp);
fwrite($fp, "<a href=http://www.htmlforums.com/archive/index.php/\"aim:goim?ScreenName=$who\">$who</a>: $gbook<br>\n" . $old_data);
flock($fp,3);
fclose($fp);
chmod($file_name 0777);
umask($oldmask);
and I told you to use unlink() on the file.
if you run this in the directory right above the the one you cannot delete it should delete it.
$file_name = "$dir/$sn/gbook.txt";
unlink($file_name);
switch ($option2)
{
case 'sign':
echo("<center>Thanks for signing my guest book! You can now view it in my profile!</center>");
$file_name = "$dir/$sn/gbook.txt";
$fp=fopen("$file_name", "a+");
flock($fp, 2);
$old_data = fread($fp, ($file_name));
rewind($fp);
fwrite($fp, "<a href=http://www.htmlforums.com/archive/index.php/\"aim:goim?ScreenName=$who\">$who</a>: $gbook<br>\n" . $old_data);
flock($fp,3);
fclose($fp);
break;
default:
$who = str_replace("_", " ", "$who");
echo("Sign $sn's Profile Guestbook\n");
echo("<form name=\"book\">\n");
echo("<input type=hidden name=\"option2\" value=\"sign\">\n");
echo("<input type=hidden name=\"sn\" value=\"$sn\">\n");
echo("Screen Name:<input type=\"text\" name=\"who\" value=\"$who\"><br>");
echo("Message:<textarea name=\"gbook\" wrap=\"physical\" rows=\"5\" cols=\"39\"></textarea><br>");
echo("<input type=\"submit\" value=\"Sign It\"></center>");
echo("</form>");
break;
So could someone please tell me what I have wrong?instead of a+ use r+well now for some reason it's not rewriting the old data. When someone tries to add something its just overwrites all the old stuff with the new stuff. Any thoughts?alrite..so now i do have a question i dont know the answer to. When someone signs the guestbook that i have successfully created (thanks for the help ) it makes a gbook.txt file in the user's folder. But now say i need to delete a user..like one i just wanted to test scripts on, when i go to delete the files in my FTP client, it tells me that i dont have permission to delete them. So how do i go in and delete these files and folders. Any thoughts?ok try this
$oldmask = umask(0);
$file_name = "$dir/$sn/gbook.txt";
$fp=fopen("$file_name", "a+");
flock($fp, 2);
$old_data = fread($fp, ($file_name));
rewind($fp);
fwrite($fp, "<a href=http://www.htmlforums.com/archive/index.php/\"aim:goim?ScreenName=$who\">$who</a>: $gbook<br>\n" . $old_data);
flock($fp,3);
fclose($fp);
chmod($file_name, 0777);
umask($oldmask);
don't ask but it just works. um..yeah..it didnt work. So any other ideas? Like is there a script i can use that you enter the file and the path and it just deletes the file? Mad confused, any thoughts?umm yeah did you get an error?
try this way
$oldmask = umask(0);
$file_name = "$dir/$sn/gbook.txt";
$fp=fopen("$file_name", "a+");
flock($fp, 2);
$old_data = fread($fp, ($file_name));
rewind($fp);
fwrite($fp, "<a href=http://www.htmlforums.com/archive/index.php/\"aim:goim?ScreenName=$who\">$who</a>: $gbook<br>\n" . $old_data);
flock($fp,3);
fclose($fp);
exec(chmod $file_name 0777);
umask($oldmask);
if you want to delete a file you use unlink(file_name) and if you want to delete a folder you use rmdir($dir);
but you have to have the folder empty first.when i add that the gbook.php?sn=whatever page comes up blank..well i figured out that the problem occurs with the
exec(chmod $file_name 0777);
line but i dunno how to fix it.well i changed that line to
chmod ("$file_name", 0777);
but i still can't delete the file in my FTP client. Is this something im still doing wrong or should i contact the people who provide my server and ask for help?Just chmod the file to 777 in your FTP client and delete.
Good luck,
Paulwhen i try and chmodd it it says "550 gbook.txt: Operation Not Permitted"and when i try and delete it it says "550 gbook.txt: Permission Denied"that is why I said to do this
$oldmask = umask(0);
$file_name = "$dir/$sn/gbook.txt";
$fp=fopen("$file_name", "a+");
flock($fp, 2);
$old_data = fread($fp, ($file_name));
rewind($fp);
fwrite($fp, "<a href=http://www.htmlforums.com/archive/index.php/\"aim:goim?ScreenName=$who\">$who</a>: $gbook<br>\n" . $old_data);
flock($fp,3);
fclose($fp);
chmod($file_name 0777);
umask($oldmask);
and I told you to use unlink() on the file.
if you run this in the directory right above the the one you cannot delete it should delete it.
$file_name = "$dir/$sn/gbook.txt";
unlink($file_name);