Hiding a link..

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
snicolas
Forum Commoner
Posts: 97
Joined: Tue Nov 09, 2004 8:32 am

Hiding a link..

Post by snicolas »

SOmebody has an example on how to do this?

I propose my members to download the document X, but would like to keep the location of this document "secret"

What can i do to hide the <a href="docs/document.doc"> LINK?

ta

s
snicolas
Forum Commoner
Posts: 97
Joined: Tue Nov 09, 2004 8:32 am

Post by snicolas »

Found my solution and posting it , thought it might be usefull for others...

So if you want to allow the download of important document without giving a straight url
ex: <a href="DOCUMENT.ZIP">DOC</a>

So to do

1/ Create a folder with reading permissions outside your webroot (/user/home/FOLDER NAME)
2/ Create a file called download.php and copy this code
<?php
$file= $_GET["file"];

if (!isset($file)) {

echo "<font face=\"tahoma\" size=\"2\">No File Specified</font>\n";

} else {

header("Cache-control: private");
header("Content-Type: application/force-download; name=\"$file\"");
header("Content-Disposition: attachment; filename=\"$file \"");
header("Content-Transfer-Encoding: binary");

$fp = fopen('/usr/home/FOLDER NAME/'.$file,"r");
fpassthru($fp);
fclose($fp);

}

?>
3/ In your web page, where you want to display the link for downlaod, do:
<a href="download.php?file=DOCUMENT.ZIP">DOCUMENT</a>

et voila...

Merry christmas

s
html20009876
Forum Newbie
Posts: 3
Joined: Sun May 04, 2008 3:42 am

Re: Hiding a link..

Post by html20009876 »

Hi snicolas,

Your reply is a wonderful help for me.

Cheers
Post Reply