2015-04-01 105 views
0

我有一个控制器将图像上传到我的Web服务器。我希望在该过程中将该图像上传到Dropbox。我会怎么做?如何将文件从codeigniter应用程序上传到Dropbox

这是我简单的upload.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); 

} 
+1

一个好的开始就是看[Dropbox API](https://www.dropbox.com/developers/core/start/php),甚至是专门为codeigniter编写的插件,[就像这样](https://github.com/jimdoescode/CodeIgniter-Dropbox-API-Library) – Darren 2015-04-01 07:40:32

+0

Dropbox是否支持电子邮件上传Imgur文件?这将很容易设置 – Marie 2015-04-01 13:59:12

回答

-1

尝试这个它的工作良好,为下拉框创建一个新的文件夹,只是复制过去的URL而不是“/上传”替换/下拉框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"; 
+0

不会工作,因为它不在同一台服务器上,更不用说Dropbox不会接受它。 – Darren 2015-04-01 07:49:01

+0

你使用api意味着它可以工作一次...... – 2015-04-02 09:59:23

相关问题