我可以关注我的符号链接吗?
我正在尝试从一个目录下载文件,而该文件实际上存在于另一个目录中。
我已经得到了实际的文件和单独子目录中的符号链接,但两者都驻留在公共 html 中(两者都可以通过网络访问)。
我已通过直接转到文件来验证我的(共享 Linux)服务器上的文件和文件位置。
正在创建链接(我使用了readlink、is_link和linkinfo),当我FTP进去时可以看到它。
我相信我可能只是对目录结构有误解。
我将文件放在这里:./testdownload/
我将符号链接放在这里:./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>
一切看起来都对我来说......但链接不起作用。 帮忙吗?
最终,我会将源数据放在公共区域之外......这只是为了测试。
(我正在尝试找到一个更好的下载解决方案,而不是将 fread 分块,因为连接不良而失败。(200-400MB 文件))
我的问题(似乎)是没有提供符号链接的绝对路径。
我已将下面的绝对路径添加到上面的相同代码中,以提供工作副本:
<?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>
这个原始帖子是重复的(尽管我直到现在才看到它) 为 PHP 文件创建有效的符号链接 (然而,这个问题的大多数答案都是错误的——但原始发帖者解决了这个问题,而且它对我也有用)