问题
I have a controller to upload image to my web server. I want to upload that image to dropbox as well during the process. how would I do it?
This is my simple upload.php controller:
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:
This blogpost has complete tutorial
how to use Dropbox api with codigniter using THIS CodeIgniter-Dropbox-API-Library
http://jimdoescode.blogspot.com/2011/07/codeigniter-dropbox-api.html
回答2:
try this its working good, for drop box create one new folder and just copy past the URL instead of" /upload " replace by /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";
来源:https://stackoverflow.com/questions/29385257/how-to-upload-file-from-codeigniter-app-to-dropbox