通过PHP API将多个文件上载到Dropbox
我试图使用Dropbox PHP Api上传文件。它工作得很好。Dropbox api中是否有用于多个文件上载的选项。或者php?中有任何异步上传概念。目前我正在使用oauth2.0进行应用程序登录通过PHP API将多个文件上载到Dropbox,dropbox,dropbox-api,dropbox-php,Dropbox,Dropbox Api,Dropbox Php,我试图使用Dropbox PHP Api上传文件。它工作得很好。Dropbox api中是否有用于多个文件上载的选项。或者php?中有任何异步上传概念。目前我正在使用oauth2.0进行应用程序登录 /** * Uploads a physical file from disk * Dropbox impose a 150MB limit to files uploaded via the API. If the file * exceeds this limit or does not
/**
* Uploads a physical file from disk
* Dropbox impose a 150MB limit to files uploaded via the API. If the file
* exceeds this limit or does not exist, an Exception will be thrown
* @param string $file Absolute path to the file to be uploaded
* @param string|bool $filename The destination filename of the uploaded file
* @param string $path Path to upload the file to, relative to root
* @param boolean $overwrite Should the file be overwritten? (Default: true)
* @return object stdClass
*/
public function putFile($file, $filename = false, $path = '', $overwrite = true)
{
if (file_exists($file)) {
if (filesize($file) <= 157286400) {
$call = 'files/' . $this->root . '/' . $this->encodePath($path);
// If no filename is provided we'll use the original filename
$filename = (is_string($filename)) ? $filename : basename($file);
$params = array(
'filename' => $filename,
'file' => '@' . str_replace('\\', '/', $file) . ';filename=' . $filename,
'overwrite' => (int) $overwrite,
);
return $this->fetch('POST', self::CONTENT_URL, $call, $params);
}
throw new Exception('File exceeds 150MB upload limit');
}
// Throw an Exception if the file does not exist
throw new Exception('Local file ' . $file . ' does not exist');
}
/**
*从磁盘上载物理文件
*Dropbox对通过API上传的文件施加150MB的限制。如果文件
*超过此限制或不存在,将引发异常
*@param string$file要上载的文件的绝对路径
*@param string | bool$filename上载文件的目标文件名
*@param string$相对于根目录上载文件的路径
*@param boolean$是否应覆盖该文件?(默认值:true)
*@return对象stdClass
*/
公共函数putFile($file,$filename=false,$path='',$overwrite=true)
{
如果(文件_存在($file)){
if(filesize($file)root.'/.$this->encodePath($path);
//如果没有提供文件名,我们将使用原始文件名
$filename=(是字符串($filename))?$filename:basename($file);
$params=数组(
'filename'=>$filename,
'file'=>'@.str\u replace('\\','/',$file)。';filename='.$filename,
'覆盖'=>(int)$overwrite,
);
返回$this->fetch('POST',self::CONTENT\u URL,$call,$params);
}
抛出新异常('文件超过150MB上载限制');
}
//如果文件不存在,则引发异常
抛出新异常(“本地文件“$file.”不存在);
}
我正在使用的这个脚本Dropbox API目前不提供任何批量或批量上传,但我们正在将其作为功能请求进行跟踪 在这种情况下,如果您想以异步方式运行此代码,您可以在另一个线程的后台运行它