如何将文件从codeigniter应用程序上传到dropbox


how to upload file from codeigniter app to dropbox

我有一个控制器可以将图像上传到我的web服务器。我想在这个过程中也将该图像上传到dropbox。我该怎么做?

这是我的简单上传.php控制器:

function index() {
    // get the binary data
    $file = file_get_contents("php://input");
    // prepare new name for upload image
    $name =rand().time().'jpg';
    $path = site_url('photo');
    // save to server directory
    file_put_contents($path.$name, $file);
    // save the name and id of the post to post photo table
    $input =  array(    'name' => $name,
                        'post_id'=> $id
                    );
    $this->db->insert('post_photo', $input);
}

这篇博客文章有完整的教程
如何使用Dropbox api和使用THISCodeIgniter-Dropbox-api-Library 的密码识别器

http://jimdoescode.blogspot.com/2011/07/codeigniter-dropbox-api.html

尝试一下它的工作原理,对于Dropbox创建一个新文件夹,只复制经过URL,而不是"/upload"替换为/drop-box URL

    $route=$_FILES['file_name']['name'];
    //var_dump($route);
    $target=realpath(APPPATH.'../uploads');
    $target=$target.'/'.$route;
    $tar=$route;
    $path=base_url().'uploads/'.$route;
    if(move_uploaded_file($_FILES['file_name']['tmp_name'],$target))
        echo "uploaded";
    else
        echo "not";