Dropbox has an API for this https://www.dropbox.com/developers/core/start/php
Easy to integrate, I think there will be no problems.
================================================
Let’s go then as requested:
=========================================
Basic instruction to the APP
- CREATE A DROPBOX APP
- Create an APP in DROPBOX https://www.dropbox.com/developers/apps/create
- Choose the "Dropbox API app" option then select "Yes - My app only needs access to files it creates."
- From a name to the APP and then you will be redirected to the APP config screen,
- set the return url where Voce will write the Autentication token
Ex:
http://localhost/dropboxAPI/end_auth.php
- On this same page will appear your APP_KEY and APP_SECRET - which will use to authenticate the APP.
=============================================
=============================================
EX:
/var/html/dropboxAPI/
e digite o comando:
composer install
- Wait for package installation to finish.
=============================================
CREATING THE ARCHIVES
For this example we are doing create the following files
- index php.
- end_auth.php
- config.php
File below 'config.php'
<?php
session_start();
function pre($arg){
echo "<pre>";
print_r($arg);
echo "</pre>";
}
require "vendor/autoload.php";
define('DROPBOX_KEY' , 'sua key');
define('DROPBOX_SECRET' , 'seu secret');
define('APP_NAME' , 'ShowRoomEvent');
# inicia classe
$app = new Dropbox\AppInfo(DROPBOX_KEY,DROPBOX_SECRET);
# metodo token verificacao
$tokenCsfr = new Dropbox\ArrayEntryStore($_SESSION,'dropbox-auth-csrf-token');
# pede autenticacao
$auth = new Dropbox\WebAuth($app,APP_NAME,'http://localhost/dropboxAPI/end_auth.php',$tokenCsfr);
?>
Below code the 'end_auth.php' (or the file you set in the APP URL)
<?php
# inicio arquivo end_auth.php
# RECEBE O TOKEN DO DROPBOX
require 'config.php';
list($getToken) = $auth->finish($_GET);
if( isset($getToken) && !empty($getToken)){
# ARMAZENAR NA SESSAO OU BD
$_SESSION['user_token'] = $getToken;
header("Location: index.php");
} else{
echo "Erro ao gerar autenticacao";
}
#fim arquivo end_auth.php
?>
index.php file with the basic examples
<?php
require 'config.php';
# se voce colocar na url ?logout=true
# vai limpara a sessao e pedir autenticacao novamemente
# lembrando que voce pode armazenar essa info no BD, XML etc...
if( isset($_GET['logout']) ){
unset($_SESSION['user_token']);
}
# verifica se tem token
if( ! isset($_SESSION['user_token']) && empty($_SESSION['user_token'])) {
# se nao tem token pede permissao para o usuario
$url = $auth->start();
header("Location: " . $url);
}
# o token ja foi armazenado na sessao conforme arquivo 'end_auth.php'
$user = new Dropbox\Client($_SESSION['user_token'],APP_NAME,'UTF-8');
$usuario = $user->getAccountInfo();
pre($usuario);
echo "<br/><br/>";
/* EXEMPLO UPLOAD
* Para fazer upload para o dropbox voce ja deve
* ter o arquivo localmente ou fazer o upload e depois
* enviar par ao drop
*
*/
$arquivo = fopen("cascata.png",'rb');
$tamanho = filesize("cascata.png");
# onde o nome cascata_no_drop.png deve ser o nome que
# vai ser usado no dropbox lembre de colocar / antes do nome
$user->uploadFile("/cascata_no_drop.png",Dropbox\WriteMode::add(),$arquivo,$tamanho);
/*
* EXEMPLO DOWNLOAD
* informar o path do arquivo no drop
* informar novo nome para o arquivo "fopen mode 'wb'"
*/
$user->getFile("/cascata_no_drop.png", fopen("cascata_vinda_drop.png","wb"));
/*
* LISTA O QUE TEM NO DROPBOX
*/
$lista = $user->getMetadataWithChildren('/');
pre($lista);
?>
Hi rafaelphp. If you play here a minimum functional example of the code your answer gets much better (because it ceases to depend so much on the link - that if it is out of the air does not help the reader at all) and gets my +1. :)
– Luiz Vieira
@Luizvieira gives a look tries ai tmb ve if you need to correct something or explain better. abs
– rafaelphp
I can’t test because I don’t have the environment installed. But, as promised, take my +1. :)
– Luiz Vieira
But this would serve in case for me to work local on the tablet, without needing internet connection? Because the idea was that I work in a local folder, in case the tablet would have Dropbox installed in it. And even if the person had no internet connection the app would have to work. The part of Dropbox, would be that if I update a file, I update all the tablets by the folder of Dropbox, as soon as the tablets access the internet.
– Leonardo Patricio
@Leonardopatricio, your question was to make the APP localhost access the Dropbox and not that you would have to use the offline Dropbox, I find it hard without internet to be able to do this with Dropbox because what Voce wants is a solution that works with Dropbox synchronizing all folders and this is only possible with internet.
– rafaelphp
@Leonardopatricio, however, is an example of how to use the api and works perfectly on localhost. But from what I understand you can do this without having to use Dropbox, only with PHP upload and download files, just Voce leave a tablet as server so all other tablets will access this, no need to have androPHP on all tablets only in one. You can put a router without internet just to make a local network and connect the tablets through this router without internet access, this will allow you to make the application offline with a tablet configured as a server.
– rafaelphp
@Leonardopatricio, or leave a notebook as a server and with fixed IP type: 192.168.1.100 so the local server is faster and can be used by the browser of the tablets, accessing in Chrome for example: http://192.168. 1.100/myPpp. I think this is the best option without using Dropbox.
– rafaelphp
Yes to the location of the event there will be a server, but due to the large number of wifi networks on site, wifi networks fall frequently, and that same system can be used when a company employee is visiting a client, so through the tablet app it can generate an order, and it is not within any wifi and may or may not have 3g, so it can not depend on the internet, only update the application files that depends on the internet, and I believe that the best way to solve this would be to use the Dropbox, which would be able to update all by 1 place.
– Leonardo Patricio
I liked your reply @rafaelphp I will be studying this api of Dropbox, but I wonder if you knew something that could suit me perfectly.
– Leonardo Patricio
@Leonardopatricio, now I understand better, Oce can make the Dropbox script save in your sync folder, so when the tablet is with internet will synchronize automatically.
– rafaelphp
Because what I was initially thinking was just my apache having as root folder a Dropbox folder, so it would be simpler for me,.
– Leonardo Patricio
or the case would be to have an application class that could update the files, pulling from some online server, in which I would make available the updated files, thus eliminating the use of Dropbox, but also do not know if this is possible with php.
– Leonardo Patricio
@Leonardopatricio, yes it is possible. I believe Oce has already unraveled the mystery.
– rafaelphp
I will be looking for information to solve this problem, take the 50 pts for their dedication in trying to help
– Leonardo Patricio