2011-02-25 65 views
2

我想一些腳本代碼,將搜索服務器在一個特定的文件擴展名的最新文件上指定的文件夾(在我的情況.zip文件)和文件傳輸到Rackspace的雲文件。下面的代碼是我得到的,我不斷收到錯誤:PHP文件傳送到Rackspace的雲文件

致命錯誤:在/ home/test /的public_html/cloudapi/cloudfiles.php:1952堆棧跟蹤:#0 /home/test/public_html/final.php(60):CF_Object-> load_from_filename(資源ID#8)#1 {主}拋出在/ home /測試/的public_html/cloudapi在線/ cloudfiles.php 1952年

,我使用下面原本是爲通過HTML上傳表單&我試圖適應相同的代碼使用本地服務器文件,而不是將內容上傳完成的代碼上傳的文件。您將看到之前用於上傳腳本的註釋代碼,以向您展示上傳腳本的工作方式。

<?php 

// include the Cloud API. 
require('cloudapi/cloudfiles.php'); 


// START - Script to find recent file with the extension .zip in current folder 
$show = 2; // Leave as 0 for all 
$dir = ''; // Leave as blank for current 

if($dir) chdir($dir); 
$files = glob('*.zip'); 
usort($files, 'filemtime_compare'); 

function filemtime_compare($a, $b) 
{ 
return filemtime($b) - filemtime($a); 
} 

$i = 0; 
foreach ($files as $file) 
{ 
++$i; 
if ($i == $show) break; 
$value = $file; //Variable $value contains the filename of the recent file to be used in Cloud Files API 
} 
// END - Script to find recent file with the extension .zip in current folder 



// START - Rackspace API code to upload content to cloud files container 
// Rackspace Connection Details; 
$username = "randomusername"; // put username here 
$key = "234887347r93289f28h3ru283h2fuh23093402398"; // api key 

// Connect to Rackspace 
$auth = new CF_Authentication($username, $key); 

$auth->authenticate(); 
$conn = new CF_Connection($auth); 

//Set the Container you want to use 
$container = $conn->get_container('Backups'); 

//Temp store the file 
//$localfile = $_FILES['uploadfile']['tmp_name']; 
//$filename = $_FILES['uploadfile']['name']; 
$localfile = fopen($value, "r"); 
$filename = $value; 


//Uploading to Rackspace Cloud 
$object = $container->create_object($filename); 
$object->load_from_filename($localfile); 

echo "Your file has been uploaded"; 

// END - Rackspace API code to upload content to cloud files container 
?> 

回答

0

由於讀取文件中未定義內容類型,因此引發錯誤。

2

我知道這是一個古老的線程。但對於誰可以在此頁面登陸,同時尋找解決人的利益......

與您的代碼的問題是:

下面的語句打開文件進行讀取

$localfile = fopen($value, "r"); 

然而,當您將load_from_filename調用,程序將再次嘗試打開相同的文件,並因爲你已經在它打開LOCALFILE $失敗。

所以註釋掉前面的命令,你應該能夠成功地運行該腳本。

相關問題