PHP将服务器上的文件传输到Rackspace云文件

我正在尝试编写一些代码,这些代码将在服务器上的指定文件夹中搜索具有特定文件扩展名的最新文件(在我的情况下为.zip),并将该文件传输到Rackspace的Cloud Files。下面的代码是我得到的,我不断收到错误: 致命错误:未捕获异常'IOException',消息'无法打开文件进行读取:资源ID#8'/home/test/public_html/cloudapi/cloudfiles.php:1952堆栈跟踪:#0 / home / test / public_html / final.php(60):CF_Object-> load_from_filename(资源ID#8)在1952行的/home/test/public_html/cloudapi/cloudfiles.php中抛出#1 {main} 我在下面使用的代码最初用于通过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
?>
    
已邀请:
我知道这是一个老线程。但是为了在寻找解决方案时可能登陆此页面的人们的利益...... 您的代码的问题是: 以下语句打开要读取的文件
$localfile = fopen($value, "r");
但是,当您放置load_from_filename调用时,例程再次尝试打开同一个文件并失败,因为您已经在$ localfile中打开它。 因此,注释掉上一个命令,您应该能够成功运行脚本。     
因为未从读取文件定义内容类型而引入错误。     

要回复问题请先登录注册