search for in the  
<stattempnam>
Last updated: Thu, 19 May 2005

symlink

(PHP 3, PHP 4, PHP 5)

symlink -- Creates a symbolic link

Description

bool symlink ( string target, string link )

symlink() creates a symbolic link from the existing target with the specified name link.

Returns TRUE on success or FALSE on failure.

Note: This function is not implemented on Windows platforms.

See also link() to create hard links, and readlink() along with linkinfo().



User Contributed Notes
symlink
11-May-2005 01:12
A similar function can be achieved in Windows (NTFS) using folder or file junction points. 

There are 2 free apps for this:

-Junction Link Magic for folders
http://www.rekenwonder.com/linkmagic.htm

-Hardlink Shell Extension for files
 http://hermann.schinagl.tripod.com/nt/hardlinkshellext
aircha at cix dot co dot uk
15-Mar-2005 10:49
Olszewski's method of creating downloadable links on the fly is pretty good.

I use a different technique under Apache where if you want a file, you might use a url like:

mydomain.com/files/mysecretfile.doc

But in fact Apache redirects this to a script with a url like:

mydomain.com/utilities/downloadfile.php?filename=mysecretfile.doc

(The browser address bar will still show the first url).

The script downloadfile.php can then handle all the mucky stuff like checking session variables to see if someone is logged on, whether they have access to mysecretfile.doc, and if you want to encrypt before download.

An advantage of this is that the php code to achieve the equivalent of Olszewski's is shorter, so might execute faster. But more importantly, a casual hacker might think all he has to do is find myverysecurefile.doc under the /home/user/public_html/files/mysecretfile.doc, or copy the url - but there's nothing there! He won't find it or get an Apache error page.
khaireel at gmail dot com
17-Oct-2004 11:27
I find olszewski's method of utilizing symlink is great. Solved my problem of hiding the URLs that I dont wish users to know about.

Although, just to point out, I had to write a special page (or condition on a page) to allow the download process to be effective. The server wont allow direct downloads from the $downloadURL.
veronique at talafone dot com
29-May-2003 04:23
This might sound obvious, but sometimes these details slip from our minds...
Make sure the directory in which you are trying to create the symbolic link (AND the directory you are trying to link to in the case of directory linking) has the proper permissions, or you will get a "permission denied" from PHP. If you use for example,
echo shell_exec("ln -sv $target $name")
you might get the correct "link created" message, but without the link being actually created.

It's probably the same thing with hard links, I just haven't tried it.
stephen at opido dot com
07-Feb-2002 02:38
Faking Symlinks on Windows (Win2K + NTFS)

Every once in a while I'll bang my head against something really difficult. I needed to make symlinks, Windows won't let me. The workaround is a couple files in the Win2K Resource Kit called linkd.exe and delrp.exe

http://support.microsoft.com/default.aspx?scid=kb;EN-US;q205524

It only works on folders as far as I can tell, there is another program from SysInternals called Junction which will do both (although I only had success with files, not folders).

http://www.sysinternals.com/ntw2k/source/misc.shtml#junction

I hope this helps those who have experienced this same problem. One step closer to portable applications :)
olszewski_marek at yahoo dot com
04-Dec-2000 10:54
Here is a simple way to control who downloads your files...

You will have to set: $filename, $downloaddir, $safedir and $downloadURL.

Basically $filename is the name of a file, $downloaddir is any dir on your server, $safedir is a dir that is not accessible by a browser that contains a file named $filename and $downloadURL is the URL equivalent of your $downloaddir.

The way this works is when a user wants to download a file, a randomly named dir is created in the $downloaddir, and a symbolic link is created to the file being requested.  The browser is then redirected to the new link and the download begins.

The code also deletes any past symbolic links created by any past users before creating one for itself.  This in effect leaves only one symbolic link at a time and prevents past users from downloading the file again without going through this script.  There appears to be no problem if a symbolic link is deleted while another person is downloading from that link.

This is not too great if not many people download the file since the symbolic link will not be deleted until another person downloads the same file.

Anyway enjoy:

$letters = 'abcdefghijklmnopqrstuvwxyz';
srand((double) microtime() * 1000000);
$string = '';
for ($i = 1; $i <= rand(4,12); $i++) {
   $q = rand(1,24);
   $string = $string . $letters[$q];
}
$handle = opendir($downloaddir);
while ($dir = readdir($handle)) {
   if (is_dir($downloaddir . $dir)){
     if ($dir != "." && $dir != ".."){
         @unlink($downloaddir . $dir . "/" . $filename);
         @rmdir($downloaddir . $dir);
     }
   }
}
closedir($handle);
mkdir($downloaddir . $string, 0777);
symlink($safedir . $filename, $downloaddir . $string . "/" . $filename);
Header("Location: " . $downloadURL . $string . "/" . $filename);
shrike at il dot fontys dot nl
08-Jun-1999 11:48
symlink doesn't check if a target is present (at least 3.0.9-linux doesn't). Fortunately, since you can still store info in the target-part of a symlink.

<stattempnam>
 Last updated: Thu, 19 May 2005
Copyright © 2001-2005 The PHP Group
All rights reserved.
This unofficial mirror is operated at: The Server Pages
Last updated: Thu May 19 17:35:34 2005 CDT