符号链接和文件上传问题

发布于 2024-08-15 04:47:17 字数 906 浏览 5 评论 0原文

我遇到了这种奇怪的事情。我在本地开发的 Zend Framework (PHP) Web 应用程序在我的计算机上运行良好,但是一旦上传到服务器,它就会认为上传目录不存在。

我的应用程序有一个上传目录,它是指向应用程序外部目录的符号链接:

#local
/myapp.local
    /application
    /data
        /uploads (symlink, points to ./../../shared_uploads)
    /public/index.php
/shared_uploads

#remote
/shared_uploads
/current (symlink, points to ./releases/myapp-2009-12-18)
/releases
    /myapp-2009-12-18
        /application
        /data
            /uploads
        /public/index.php

服务器指向 /current/public/index.php 来提供应用程序。难道因为它实际上位于releases目录中,所以它更深一层吗?或者可能是权限错误,因为我在本地计算机而不是服务器上创建了上传符号链接?

更新: 在我的 /public/index.php 文件中,我定义了我的上传目录,如下所示:

// Define path to uploads directory
defined('APPLICATION_UPLOADS_DIR')
    || define('APPLICATION_UPLOADS_DIR', realpath(dirname(__FILE__) . '/../data/uploads'));

I'm having this weird thing happen. My Zend Framework (PHP) web application that I have been developing locally works fine on my computer, but once it's uploaded to the server, it thinks that the uploads directory doesn't exist.

My application has an uploads directory which is a symlink to a directory outside of the application:

#local
/myapp.local
    /application
    /data
        /uploads (symlink, points to ./../../shared_uploads)
    /public/index.php
/shared_uploads

#remote
/shared_uploads
/current (symlink, points to ./releases/myapp-2009-12-18)
/releases
    /myapp-2009-12-18
        /application
        /data
            /uploads
        /public/index.php

The server points to /current/public/index.php to serve up the application. Could it be that since it is actually in the releases directory that it's one level deeper? Or could it be a permissions error since I created the uploads symlink on my local computer instead of on the server?

Update: In my /public/index.php file I'm defining my upload dir like this:

// Define path to uploads directory
defined('APPLICATION_UPLOADS_DIR')
    || define('APPLICATION_UPLOADS_DIR', realpath(dirname(__FILE__) . '/../data/uploads'));

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

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

发布评论

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

评论(3

吖咩 2024-08-22 04:47:17

只要您的 UMASK0022,权限就不应该成为问题,但问题是您如何上传? FTP 不会尊重符号链接(尽管我相信 sftp 会尊重),而 scp 或 rsync 会。

这就是说,尽管它绝对是您的目录结构嵌套。符号链接应该相对于其父级的真实位置,因此在您的情况下,这将是 ln -s ../../../../shared_uploads。我认为最简单的解决方案是在 releases 中创建一个符号链接来引用真正的shared_uploads

The permissions shouldnt be an issue so long as your UMASK is 0022 but the question is how are you uploading? FTP isnt going to respect a symlink (though i beleive sftp does) while scp or rsync will.

Whit that said though its definitely your directory structure nesting. the symlink is should be relative from the true location of its parent so in your case thats going to be ln -s ../../../../shared_uploads. i think the easiest solution here would be to make a symlink within releases to refer to the real shared_uploads.

得不到的就毁灭 2024-08-22 04:47:17

这有帮助吗?

defined('APPLICATION_UPLOADS_DIR') || define('APPLICATION_UPLOADS_DIR', dirname(dirname(realpath(__FILE__))) . '/data/uploads');

我使用两个 dirname() 删除了 ..,并且之前运行了 realpath() 以从路径中删除符号链接。

尽管我怀疑您根本不需要 realpath()

再见!

Does this help?

defined('APPLICATION_UPLOADS_DIR') || define('APPLICATION_UPLOADS_DIR', dirname(dirname(realpath(__FILE__))) . '/data/uploads');

I removed the .. by using two dirname()s and I ran realpath() earlier to remove the symlink from the path.

Though I suspect you don't need the realpath() at all.

Ciao!

萌梦深 2024-08-22 04:47:17

使用传输 FTP 应用程序时,当您同步“遵循符号链接”时,会有一个复选框,这似乎对我有用。

Using Transmit FTP app there is a checkbox when you sync "Follow symbolic link" that seems to work for me.

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