1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
| <!DOCTYPE html>
<html lang="fr-FR">
<head>
<meta charset="UTF-8">
<script type="text/javascript" src="https://www.dropbox.com/static/api/2/dropins.js" id="dropboxjs" data-app-key="APP-KEY"></script>
<script>
options = {
success: function(files) {
var url = location.href;
//Récupération du token (et du reste, à améliorer)
var code = url.substring(42);
//Modification du lien pour récupérer un fichier depuis le compte Dropbox de l'utilisateur
document.getElementById('dl').setAttribute('href', "index.php?file="+files[0].link+"&file_name="+files[0].name+"&"+code);
document.getElementById('dl').innerHTML = files[0].name;
//Pour montrer le fonctionnement du saver
document.getElementById('saver').setAttribute('href', files[0].link);
},
cancel: function() {
},
linkType: "direct"
multiselect: false
extensions: ['.pdf', '.doc', '.odt'],
};
</script>
</head>
<body>
<?php
//Lien pour obtenir le token nécessaire à l'accès au compte Dropbox de l'utilisateur
$app_code = "APP-KEY";
$url_redirect = "http://url/redirection.php";
echo "<a href=\"https://www.dropbox.com/1/oauth2/authorize?client_id=$app_code&response_type=token&redirect_uri=$url_redirect\">Test</a>";
?>
<h3>Test API DropBox</h3>
<button onclick="Dropbox.choose(options)">Ouvrir un fichier Dropbox</button>
<a id="dl" href=""></a>
<br />
<?php
if(isset($_GET['file_name'])){
$ch = curl_init(str_replace(" ","%20",$_GET['file']));
$fp = fopen(dirname(__FILE__) . "/Files/" . $_GET['file_name'], 'w+');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FILE, $fp);
//Désactivation des vérifications
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$response = curl_exec($ch);
if($response == true){
echo 'file downloaded';
}
else echo 'un problème est survenu';
curl_close($ch);
}
?>
<br />
<br />
<!-- Pour utiliser le saver Dropbox, il suffit de donner la classe "dropbox-saver" à un lien.
Le fichier fourni dans l'attribut href sera uploadé sur le compte Dropbox de l'utilisateur -->
<a id="saver" href="http://www.corsaire-editions.com/pub/fond-ecran-chaton.jpg" class="dropbox-saver">Save to dropbox</a>
<br />
</body>
</html> |
Partager