특정 파일 확장자 (내 경우 .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
?>