我正在尝试编写一些代码,这些代码将在服务器上的指定文件夹中搜索具有特定文件扩展名(在我的情况下为 .zip)的最新文件,并将该文件传输到 Rackspace 的云文件。下面的代码是我得到的,我不断收到错误:
致命错误:在 /home/test/public_html/cloudapi/cloudfiles.php:1952 中,未捕获的异常“IOException”带有消息“无法打开文件进行读取:资源 ID #8”堆栈跟踪:#0 /home/test/public_html/ final.php(60): CF_Object->load_from_filename(Resource id #8) #1 {main} 在第 1952 行的 /home/test/public_html/cloudapi/cloudfiles.php 中抛出
我在下面使用的代码最初是为通过 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
?>