【问题标题】:Sharing image folder between two domains cakephp在两个域之间共享图像文件夹 cakephp
【发布时间】:2012-08-03 07:05:43
【问题描述】:

我有一个网站和一个子域,允许用户将图像上传到他们的帐户,这两个域是 cakephp 应用程序,它们共享相同的 CakeLib 但不同的应用程序目录。我希望能够从另一个域访问从任一域上传的图像(例如,如果用户进入子域并上传图像,我应该能够从父域访问相同的图像并且反之亦然) .

请注意,访问此图像是严格在视图中完成的。我会很感激任何建议。

谢谢

【问题讨论】:

    标签: cakephp dns sharing subdomain


    【解决方案1】:
    $this->Html->image('http://subdomain.example.com/image.png');
    

    类似上面的东西? :o,你也可以扩展你的助手:

    class MyAppHelper extends AppHelper {
        public $helpers = array('Html');
    
        public function subdImage($path) {
            return $this->Html->image('http://subdomain.example.com/' . $path);
        }
    }
    

    并从您的视图中调用它,例如:

    $this->MyApp->subdImage('image.png');
    

    【讨论】:

    • 谢谢,但我希望避免对图像进行跨域调用,因为如果我在本地访问图像会花费相当长的时间。这就是为什么我没有在一开始就使用这种策略
    • 您确定需要更长的时间吗?它们都由同一客户端从同一主机提供服务。
    • @sfagade 慢是什么意思? :o,如果它们是从两个不同的域托管的(子域的处理方式不同),浏览器可以并行加载不同的图像,如果有的话,这应该会让你的应用程序更快。 developer.yahoo.com/performance/rules.html#js_bottomThe HTTP/1.1 specification suggests that browsers download no more than two components in parallel per hostname. If you serve your images from multiple hostnames, you can get more than two downloads to occur in parallel.
    • 谢谢,这就是我需要知道的全部内容。非常感谢
    • 很高兴我能帮上忙 :),您可以通过单击我的答案旁边的空心“V”符号来感谢我。 meta.stackexchange.com/questions/5234/…
    【解决方案2】:

    只需symlink 文件夹即可。我会让我的上传路径可配置,例如指向 /home/www-data/images 并将其符号链接到 /var/www/app1/webroot/img 和 /var/www/app2/webroot/img 等两个应用程序。根本不需要代码。符号链接也适用于 Windows。

    【讨论】:

    • 谢谢,但我认为您不能在 cpanel 共享主机上创建符号链接。你能
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-06-04
    • 1970-01-01
    • 2019-12-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-29
    相关资源
    最近更新 更多