简体   繁体   English

使用PHP中的Dropbox API在Dropbox中上传图片文件

[英]uploading image file in dropbox using dropbox api in php

How can I upload image files to Dropbox with the Jimscode PHP Dropbox component for CodeIgniter? 如何使用CodeIgniter的Jimscode PHP Dropbox组件将图像文件上传到Dropbox? It uses the add() method for uploading files. 它使用add()方法上传文件。 It successfully uploads all other files types (eg pdf) to Dropbox. 它成功地将所有其他文件类型(例如pdf)上传到Dropbox。 But when I upload image files, it uploads empty files to Dropbox. 但是,当我上传图像文件时,它会将空文件上传到Dropbox。 That is of 0 bytes and unable to preview that image in Dropbox. 这是0个字节,无法在Dropbox中预览该图像。 My code: 我的代码:

public function add($dbpath, $filepath, array $params = array(), $root=self::DEFAULT_ROOT)
    {
        $dbpath = str_replace(' ', '%20', $dbpath);
        $filename = rawurlencode($filepath);
        $parstr = empty($params) ? '' : '&'.http_build_query($params);
        $uri = "/files_put/{$root}/{$dbpath}?file={$filename}{$parstr}";
        //$uri = reduce_double_slashes("/files/{$root}/{$dbpath}?file={$filename}{$parstr}");
        $specialhost = 'api-content.dropbox.com';
        return $this->_post_request($uri, array('file'=>'@'.$filepath), $specialhost);
    }

Is there an API method I can use directly with curl and PHP? 有没有可以直接用于curl和PHP的API方法?

I'm not sure what version you are using but the reduce_double_slashes line isn't commented out normally. 我不确定您使用的是哪个版本,但是reduce_double_slashes行没有被正常注释掉。 That wouldn't cause some file types to upload and not others though. 但这不会导致某些文件类型上载,而不会导致其他文件类型上载。 Is the failure with a single image or does it fail to upload with every image. 是单个图像失败,还是每个图像都上传失败?

You can also set the DEBUG const in the library to true and have it write debug information out to your error log. 您还可以将库中的DEBUG常量设置为true,并使其将调试信息写到错误日志中。 That might help you figure out where the issue is happening. 这可以帮助您弄清楚问题出在哪里。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM