2011-02-25 4 views
2

특정 파일 확장자 (내 경우 .zip)가 포함 된 최신 파일을 서버의 지정된 폴더에서 검색하고 해당 파일을 Rackspace 's로 전송하는 코드를 스크립팅하려고합니다. 클라우드 파일. 아래 코드는 오류가 계속 발생하여 계속 표시됩니다.서버의 PHP 전송 파일을 Rackspace 클라우드 파일로

치명적인 오류 :/home/test /에서 '읽을 파일을 열 수 없습니다.'라는 메시지가있는 'IOException' public_html/cloudapi/cloudfiles.php : 1952 스택 추적 : # 0 /home/test/public_html/final.php(60) : CF_Object-> load_from_filename (리소스 ID # 8) # 1 {main}/home/test/public_html/cloudapi/cloudfiles.php on line 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에서 이미 열려 있기 때문에 실패합니다.

이전 명령을 주석 처리하면 스크립트를 성공적으로 실행할 수 있습니다.

관련 문제