求助 CodeIgniter 集成七牛 CDN 的问题

2019-04-17 22:38:35 +08:00
 care

买了个老外的 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');

2977 次点击
所在节点    PHP
6 条回复
runningman
2019-04-17 22:41:21 +08:00
干啥的脚本
HiCode
2019-04-17 22:44:24 +08:00
既然 500,就修改 php 的错误提示,把具体的错误信息打出来再说。
care
2019-04-17 22:46:20 +08:00
@runningman 就是替换访问静态图片资源的域名为 cdn 加速域名
runningman
2019-04-17 22:50:43 +08:00
@care 这个 ci 直接就支持吧。
care
2019-04-17 23:05:35 +08:00
@HiCode 搞错了,是只有一个 200 的状态码,页面一片空白[200]( http://resume.wmysummer.com:3100/image/200.png)
care
2019-04-17 23:06:47 +08:00
@runningman 我不是专业的编程人员 o.o,还望大佬指点下。谢谢!

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/556200

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX