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

PHP将服务器上的文件传输到Rackspace云文件,php,file,cloud,transfer,rackspace,Php,File,Cloud,Transfer,Rackspace,我正在尝试编写一些代码,这些代码将在服务器上的指定文件夹中搜索具有特定文件扩展名(在我的示例中为.zip)的最新文件,并将该文件传输到Rackspace的云文件。下面的代码是我得到的,我不断得到错误: 致命错误:未捕获异常“IOException”,消息为“无法打开/home/test/public#html/cloudapi/cloudfiles.php中的文件进行读取:资源id#8”。php:1952堆栈跟踪:#0/home/test/public#html/final.php(60):CF

我正在尝试编写一些代码,这些代码将在服务器上的指定文件夹中搜索具有特定文件扩展名(在我的示例中为.zip)的最新文件,并将该文件传输到Rackspace的云文件。下面的代码是我得到的,我不断得到错误:

致命错误:未捕获异常“IOException”,消息为“无法打开/home/test/public#html/cloudapi/cloudfiles.php中的文件进行读取:资源id#8”。php:1952堆栈跟踪:#0/home/test/public#html/final.php(60):CF_对象->从文件名(资源id#8)#1{main}在1952行的/home/test/public_html/cloudapi/cloudfiles.php中抛出

我在下面使用的代码最初是通过html上传表单上传内容的&我正在尝试修改相同的代码,以使用本地服务器文件而不是上传的文件。您将看到一个上传脚本的带有was的注释代码,以向您展示上传脚本是如何工作的

<?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中打开了该文件

因此,注释掉前面的命令,您应该能够成功运行脚本