我想一些脚本代码,将搜索服务器在一个特定的文件扩展名的最新文件上指定的文件夹(在我的情况.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
?>