【问题标题】:cloudfiles remote file problemcloudfiles远程文件问题
【发布时间】:2011-03-14 00:33:52
【问题描述】:

我正在尝试将文件从远程文件加载到我的云文件容器。

以下是 Cloud Files 支持人员给我的示例代码:

<?php

    require('cloud/cloudfiles.php');

    $res  = fopen("http://images.piccsy.com/cache/images/66653-d71e1b-320-469.jpg", "rb");
    $temp = tmpfile();
    $size = 0.0;
    while (!feof($res))
    {
        $bytes = fread($res, 1024);
        fwrite($temp, $bytes);
        $size += (float) strlen($bytes);
    }

    fclose($res);
    fseek($temp, 0);

    //
    $auth = new CF_Authentication('user','token ');
    //Calling the Authenticate method returns a valid storage token and allows you to connect to the CloudFiles Platform.
    $auth->authenticate();

    $conn = new CF_Connection($auth);

    $container = $conn->create_container("example");
    $object = $container->create_object("example.jpg");
    $object->content_type = "image/jpeg";
    $object->write($temp, $size);

    fclose($temp);
?>

我遇到的问题是以下错误:

Fatal error: Call to a member function create_container() on a non-object in /home2/sharingi/public_html/daily_dose/remote_test.php on line 24

不确定我在这里没有注意到什么。

【问题讨论】:

    标签: php cloudfiles


    【解决方案1】:

    $conn 似乎没有成功实例化一个对象。这就是问题所在,但解决方案并不明确。

    CF_Connection 定义了吗? error_reporting(E_ALL) 会给你更多有用的信息吗? var_dump($conn instanceof CF_Connection) 输出什么?

    这应该为您指明正确的方向。

    【讨论】:

    • 应该在cloudfiles.php 中,如果不是CF_Auth 之前似乎会出错?
    • var_dump 返回Notice: Undefined variable: conn in /home2/sharingi/public_html/daily_dose/remote_test.php on line 5 bool(false)error_reporting 返回Notice: Undefined offset: 8 in /home2/sharingi/public_html/daily_dose/cloud/cloudfiles.php on line 1588
    • 从头开始。如果我在调用$conn 之后放置var_dump,它会返回bool(true)
    猜你喜欢
    • 2018-07-20
    • 2010-10-29
    • 2011-06-18
    • 1970-01-01
    • 2016-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多