1

Can I get an eyeball on my symlink?

I'm trying to download a file from one directory, while the file actually exists in another.

I've got the actual file, and the symlink in seperate subdirectories, but both reside in the public html(both are web accessible).

I've verified the file and file location on my (shared Linux) server by going to the file directly.

The link is being created (I've used readlink, is_link, and linkinfo), and I can see it when I FTP in.

I believe I am probably just having a misunderstanding of the directory structure.

I put the file here: ./testdownload/

I put the symlink here: ./testDelivery/

<?php
$fileName = "testfiledownload.zip";//Name of File
$fileRepository = "./testdownload/";//Where the actual file lives
$downloadDirectory = "./testDelivery/";//Where the symlink lives
unlink($downloadDirectory . $fileName);  // Deletes any previously exsisting symlink (required)
symlink($fileRepository . $fileName, $downloadDirectory . $fileName); 
$checkLink = ($downloadDirectory . $fileName);
if (is_link($checkLink))
{
    echo ("<br>Symlink reads: " .readlink($checkLink) . "<br>");
    echo ("<br>LinkeInfo reads: " . linkinfo($checkLink));
}
?>
<p><a href="<?php echo ("/testDelivery/" . $fileName); ?>"</a>SymLink</p>
<p><a href="<?php echo ("/testdownload/" . $fileName); ?>"</a>regular link</p>

Everything looks right to me....but the link won't work. Help?

Ultimately, I will put the source data outside the public area...this is just for testing.

(I'm trying to find a better solution for download than chunking out fread which fails for poor connections. (200-400MB files))

jwynn
  • 31
  • 1
  • 4
  • 3
    Are you using Apache? If so, is [`Options +FollowSymLinks`](http://httpd.apache.org/docs/2.2/mod/core.html#options) set? –  Dec 13 '12 at 22:32
  • Yes Options +FollowSymLinks is set This is just baffling to me. I can't tell if my syntax (in the above example) is wrong, or if (somehow) symlinks are not working. – jwynn Dec 17 '12 at 21:35
  • There must be something wrong with the code above. I've tried it on three (all shared however) servers, and it fails on each. It generates a 404 error...despite the fact I can see the symlink in an FTP application. – jwynn Dec 18 '12 at 16:45

1 Answers1

0

My problem (appears) to be not providing the absolute path for the symlink.

I've added the absolute path below to the same code above, to give a working copy:

<?php
$absolutepath = ( $_SERVER['DOCUMENT_ROOT']);
$fileName = "testfiledownload.zip";//Name of File
$fileRepository = "/testdownload/";//Where the actual file lives
$downloadDirectory = "/testDelivery/";//Where the symlink lives
unlink($absolutepath .$downloadDirectory . $fileName);  // Deletes any previously exsisting symlink (required)
symlink($absolutepath . $fileRepository . $fileName, $absolutepath. $downloadDirectory . $fileName); 
$checkLink = ($absolutepath . $downloadDirectory . $fileName);
if (is_link($checkLink))
{
    echo ("<br>Symlink reads: " .readlink($checkLink) . "<br>");
    echo ("<br>LinkeInfo reads: " . linkinfo($checkLink));
}
?>
<p><a href="<?php echo ("/testDelivery/" . $fileName); ?>"</a>SymLink</p>
<p><a href="<?php echo ("/testdownload/" . $fileName); ?>"</a>regular link</p>

This original post, is a duplicate (though I didn't see it until now) Create a valid symlink for PHP file (Most of the answers given for that question were wrong however--but the original poster figured it out, and it worked for me too)

Community
  • 1
  • 1
jwynn
  • 31
  • 1
  • 4