V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
care
V2EX  ›  PHP

求助 CodeIgniter 集成七牛 CDN 的问题

  •  
  •   care · 2019-04-17 22:38:35 +08:00 · 2957 次点击
    这是一个创建于 1807 天前的主题,其中的信息可能已经有所发展或是发生改变。

    买了个老外的 php 脚本,基于 CodeIgniter 框架,但是作者不提供此项支持,给了个国外 cdn 运营商的配置范例[ https://cdnsun.com/knowledgebase/integrations/codeigniter-cdn-integration ]但是我按照此配置到自己的网站,导致页面报错 error 500 所以想咨询下有没有使用 CodeIgniter 框架的大佬帮忙看下什么问题,可以请大佬喝杯咖啡:)

    1,applicaiton/config/config.php

    $config['cdn_enabled']  = true;
    $config['cdn_domain']   = 'cdn.domain.com';
    $config['cdn_protocol'] = 'https';
    
    

    2,Create a file application/helpers/cdn_helper.php

    <?php
    
    function cdn($url = null)
    {
        $url = (string) $url;
        if(empty($url))
        {
            throw new Exception('URL missing');
        }
    
        $pattern = '|^http[s]{0,1}://|i';        
        if(preg_match($pattern, $url))
        {
            throw new Exception('Invalid URL. ' .
                'Use: /image.jpeg instead of full URI: ' .
                'https://domain.com/image.jpeg.'
            );
        }
            
        $pattern = '|^/|';        
        if(!preg_match($pattern, $url))
        {
            $url = '/' . $url;
        }
    
        $currentInstance    =& get_instance();
        $cdn_enabled        = $currentInstance->config->item('cdn_enabled');
        $cdn_domain         = $currentInstance->config->item('cdn_domain');
        $cdn_protocol       = $currentInstance->config->item('cdn_protocol');
    
        if(empty($cdn_enabled))
        {
            return $url;
        }
        else
        {
            return $cdn_protocol . '://' . $cdn_domain . $url;
        }    
    }   
    
    

    3,Add the following to the CodeIgniter's application/config/autoload.php file.

    
    $autoload['helper'] = array('cdn');
    
    
    6 条回复    2019-04-17 23:06:47 +08:00
    runningman
        1
    runningman  
       2019-04-17 22:41:21 +08:00 via iPhone
    干啥的脚本
    HiCode
        2
    HiCode  
       2019-04-17 22:44:24 +08:00
    既然 500,就修改 php 的错误提示,把具体的错误信息打出来再说。
    care
        3
    care  
    OP
       2019-04-17 22:46:20 +08:00
    @runningman 就是替换访问静态图片资源的域名为 cdn 加速域名
    runningman
        4
    runningman  
       2019-04-17 22:50:43 +08:00
    @care 这个 ci 直接就支持吧。
    care
        5
    care  
    OP
       2019-04-17 23:05:35 +08:00
    @HiCode 搞错了,是只有一个 200 的状态码,页面一片空白[200]( http://resume.wmysummer.com:3100/image/200.png)
    care
        6
    care  
    OP
       2019-04-17 23:06:47 +08:00
    @runningman 我不是专业的编程人员 o.o,还望大佬指点下。谢谢!
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1127 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 18:46 · PVG 02:46 · LAX 11:46 · JFK 14:46
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.