带符号链接的 PHP 文件下载

发布于 2024-10-05 20:35:00 字数 205 浏览 0 评论 0原文

我有一堆 .tgz 文件,可以通过以下方式访问。符号链接。当我点击页面上指向符号链接的 href 时,它会下载一个相当奇怪的文件。下载的文件具有符号链接的名称,打开存档后,我得到(据我所知)一个二进制文件,它可能是也可能不是静态文件的内容。

我想做的是让 PHP 显示一个文件下载对话框,该对话框提供由符号链接链接的文件,而不是实际的符号链接。这可能吗?

I have a bunch of .tgz files that are made accessible via. symlinks. When I click on the href on my page pointing to the symlink, it downloads a rather strange file. The downloaded file has the name of the symlink, and upon opening the archive I get (from what I can tell) a binary file, which may or may not be to contents of the static file.

What I'd like to do is get PHP to show a file download dialogue that gives the file linked by the symlink, not the actual symlink. Is that possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦毁影碎の 2024-10-12 20:35:00

为了给您一个准确的答案,我需要更多地了解您如何提供文件。
为什么还要涉及php?该文件不是由网络服务器提供的吗?您是否重定向到它或从打印它的位置将其读入 php 脚本中的内存?

但我可以告诉你这一点。

PHP 在大多数情况下确实将符号链接作为文件处理,并且不会无缝地提供链接后面的文件。

php 函数 is_link() 可以检查资源指针是否是链接,
有一个函数 readlink() 可以为链接后面的文件提供服务,还有一个 linkinfo() 可以为您提供有关链接的信息。

但很可能您需要明确允许 Apache 或您使用的任何服务器遵循符号链接,这些符号链接可以通过 apache 中的 Options FollowSymLinks 指令进行动态调整。

Well to give you an exact answer I would need to know more about how you serve the file.
Why is php even involved? isn't the file served by the webserver? Do you redirect to it or read it into memory in your php script from where you print it?

But I can tell you this.

PHP does in most cases handle symlinks as files, and doesn't samlessly serve the file behind the link.

There are the php functions is_link() to check if a resource pointer is a link,
there is the function readlink() to serve the file behind a link and there is linkinfo() which gives you information about the link.

But most likely you need to explicitly allow Apache or whatever server you are using to follow symlinks which can be dyne witht he Options FollowSymLinks directive in apache.

无远思近则忧 2024-10-12 20:35:00

PHP 有 readlink ,允许您获取其目标/链接到的路径。< br>
但是,认为您的问题与 apache 重写或绝对路径(再次)有关

PS: 您的 apache mime 支持 tgz 扩展吗?

参考:http://www.w3schools.com/media/media_mimeref.asp

PHP has readlink that allow you get the path that it targeted/linked to.
However, think your problem is related to apache rewrite, or absolute path (again)

PS : did tgz extensions supported by your apache mime?

refer : http://www.w3schools.com/media/media_mimeref.asp

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文