我想创建一个表单,使用Core API将文件上传到Dropbox:
require_once('dropbox-php/lib/Dropbox/autoload.php');
use \Dropbox as dbx;
if ($_POST) {
$file_to_upload = $_POST['file_to_upload'];
// Connect to Dropbox using the configuration in the app-info.json file
$appInfo = dbx\AppInfo::loadFromJsonFile("wp-content/themes/blankwptheme/app-info.json");
$accessToken = "jNw7IwVafasfasdfadfasdfsK_4-S4sfmO2vyafdafadsfa25BhC";
$dbxClient = new dbx\Client($accessToken, "PHP-Example/1.0");
$accountInfo = $dbxClient->getAccountInfo();
// Upload File to Dropbox
$f = fopen($file_to_upload, "rb");
$result = $dbxClient->uploadFile("/Uploads/" . $file_to_upload, dbx\WriteMode::add(), $f);
fclose($f);
print_r($result);
}
<form method="post">
<input type="file" name="file_to_upload" size="40">
<input type="submit" value="Submit" />
</form>
当我使用存储在服务器上的文件的硬编码路径时,代码工作正常:
$f = fopen("text.txt", "rb");
$result = $dbxClient->uploadFile("/Uploads/text.txt", dbx\WriteMode::add(), $f);
但我希望用户能够使用表单在他们的计算机上选择一个文件,然后将其上传到Dropbox。
我的问题是该文件应该已经在服务器上了......有没有办法绕过这一步?
谢谢!