2011-03-14 57 views
1

我想從遠程文件加載文件到我的雲文件容器。雲文件遠程文件問題

下面的示例代碼中的雲文件支持的人給了我:

<?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 

不知道到底是什麼,我這裏沒有注意到。

回答

0

看來$conn沒有成功實例化一個對象。這是問題所在,但解決方案並不明確。

CF_Connection定義? error_reporting(E_ALL)會給你更多有用的信息嗎? var_dump($conn instanceof CF_Connection)輸出什麼?

這應該指向正確的方向。

+0

應該在'cloudfiles.php'中,看起來'CF_Auth'會出錯,如果沒有? – ian 2011-03-14 00:37:47

+0

@ian仔細檢查一下,有時候假設是錯誤的。 :) – alex 2011-03-14 00:39:08

+0

'var_dump'返回'注意:未定義的變量:conn在第5行的/home2/sharingi/public_html/daily_dose/remote_test.php bool(false)'和'error_reporting'返回 '注意:Undefined offset:8 in在線1588上的/home2/sharingi/public_html/daily_dose/cloud/cloudfiles.php' – ian 2011-03-14 00:48:37