使用 PHP 将文件从 FORM 上传到 Dropbox

File Upload to Dropbox from FORM with PHP

我很亲近。我正在尝试创建一个将文件上传到我的 Dropbox 的表单,我可以使用服务器上的文件使用此处的代码使其工作:

$path = 'render.png';
$fp = fopen($path, 'rb');
ch = curl_init('https://content.dropboxapi.com/2/files/upload');
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_PUT, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_INFILE, $fp);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);curl_close($ch);
echo $response;

我确信这会奏效,但不行......

$fp = fopen($_FILES['file'], 'rb');

有人对此有快速修复吗?

这是你的问题

$fp = fopen($_FILES['file'], 'rb');

您需要使用 $_FILES 中的 tmp_name 字段,因为这是 PHP 放置在临时文件夹中的临时文件的位置。

$fp = fopen($_FILES['fred']['tmp_name'], 'rb');

其中 'fred'

name 属性的值
<input type="file" name="fred".....`
                   ^^^^^^^^^^^

看看 Flysystem。我将它与 Laravel 一起使用,但我相信它也可以独立使用。

http://flysystem.thephpleague.com/