• 0

add link help


Question

Hi I downloaded a add-link script that writes to a .txt file and prints on a site but the problem is it adds the link decreasingingly (as in new added link is written into the .txt file below an old one such as:

Previously added link

presviously added link

most recently added link.

How can I modify this addlink.php to write in opposite order? Thankx you in advance.

<?php

$submit = "Add URL";

if ($action == "$submit") {

function Stripn($name)

{

$name = str_replace("'", "''", $name);

return $name;

}

function Stripd($desc)

{

$desc = str_replace("'", "''", $desc);

return $desc;

}

$name = htmlspecialchars(stripslashes(Stripn($name)));

$desc = htmlspecialchars(stripslashes(Stripd($desc)));

$link_file="./links.txt";

$write = "<li type=\"circle\"> <a href=\"$url\">$name</a> | $desc<BR>\n";

$fp=fopen($link_file, "a");

fwrite($fp, $write);

fclose($fp);

echo "<b><font size=3>$name has been added!</font><BR>Thanks for your submission.</b>";

?>

<center><BR><a href="java script:window.close()">Close Window</a></center>

<?php

}

else {

print("

Add your URL:<BR>

<FORM METHOD=POST ACTION=\"$PHP_SELF\">

Site's Title: <input type=\"TEXT\" name=\"name\" size=20><BR>

Site's URL: <input type=\"TEXT\" name=\"url\" size=20 value=\"http://\"><BR>

Site's Description: <input type=\"TEXT\" name=\"desc\" size=20 maxlength=50><BR>

<center><input type=submit name=action value=\"$submit\"></center></form>

");

}

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

Replace this...

$fp=fopen($link_file, "a");
fwrite($fp, $write);
fclose($fp);

With this...

$fp=fopen($link_file, "r+");
$contents=fread($fp, filesize($link_file));
rewind($fp);
fwrite($fp, $write.$contents);
fclose($fp);

And it should add the new links at the top of the file. :)

Link to comment
Share on other sites

  • 0

Sorry WDZ yea you're right it does work (I put the edited one in anotehr directory-stupid me)thanks so much!

Hey can you maybe help me out one more time (this is what I really want to do), is how do I makes it so that it displays files ordered by date inputed ito the "name" field with newest one first such as:

032903 XXXXXXX

032803 ZZZZZZ

032803 XXXXXXX

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.