我想创建一个 PHP 脚本来将文件从我网站上的特定目录备份到我的 Dropbox 帐户。
我试图搜索示例以及如何解决它,但我只找到了备份数据库或购买现成解决方案的代码。
这是我试过的代码
<?php
$passw = "jason"; //change this to a password of your choice.
if ($_POST) {
require 'DropboxUploader.php';
try {
// Rename uploaded file to reflect original name
if ($_FILES['file']['error'] !== UPLOAD_ERR_OK)
throw new Exception('File was not successfully uploaded from your computer.');
$tmpDir = uniqid('/tmpCapes/');
if (!mkdir($tmpDir))
throw new Exception('Cannot create temporary directory!');
if ($_FILES['file']['name'] === "")
throw new Exception('File name not supplied by the browser.');
$tmpFile = $tmpDir.'/'.str_replace("/\0", '_', $_FILES['file']['name']);
if (!move_uploaded_file($_FILES['file']['tmp_name'], $tmpFile))
throw new Exception('Cannot rename uploaded file!');
if ($_POST['txtPassword'] != $passw)
throw new Exception('Wrong Password');
// Upload
$uploader = new DropboxUploader('user@example.com', 'password');// enter dropbox credentials
$uploader->upload($tmpFile, $_POST['dest']);
echo '<span style="color: green;font-weight:bold;margin-left:393px;">File successfully uploaded to my Dropbox!</span>';
} catch(Exception $e) {
echo '<span style="color: red;font-weight:bold;margin-left:393px;">Error: ' . htmlspecialchars($e->getMessage()) . '</span>';
}
// Clean up
if (isset($tmpFile) && file_exists($tmpFile))
unlink($tmpFile);
if (isset($tmpDir) && file_exists($tmpDir))
rmdir($tmpDir);
}
?>
但不是通过我的网站将图像从我的 PC 上传到 Dropbox。我想修改上面的代码,将我网站上特定目录中的文件复制到 Dropbox。