我想一些腳本代碼,將搜索服務器在一個特定的文件擴展名的最新文件上指定的文件夾(在我的情況.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
?>