Visualizzazione dei risultati da 1 a 4 su 4
  1. #1

    Script php upload file DropBox

    Ho un problema con lo script che effettua l'upload nell account dropbox ecco i file
    DropBoxUploader
    codice:
    <?php class DropboxUploader {     protected $email;     protected $password;     protected $caCertSourceType = self::CACERT_SOURCE_SYSTEM;     const CACERT_SOURCE_SYSTEM = 0;     const CACERT_SOURCE_FILE = 1;     const CACERT_SOURCE_DIR = 2;     protected $caCertSource;     protected $loggedIn = false;     protected $cookies = array();          /** * Constructor * * @param string $email * @param string|null $password */     public function __construct($email, $password) {         // Check requirements         if (!extension_loaded('cUrl'))             throw new Exception('DropboxUploader requires the cURL extension.');                  $this->email = $email;         $this->password = $password;     }          public function setCaCertificateFile($file)     {         $this->caCertSourceType = self::CACERT_SOURCE_FILE;         $this->caCertSource = $file;     }          public function setCaCertificateDir($dir)     {         $this->caCertSourceType = self::CACERT_SOURCE_DIR;         $this->caCertSource = $dir;     }      public function upload($source, $remoteDir='/', $remoteName=null) {         if (!file_exists($source) or !is_file($source) or !is_readable($source))             throw new Exception("File '$source' does not exist or is not readable.");          if (!is_string($remoteDir))           throw new Exception("Remote directory must be a string, is ".gettype($remoteDir)." instead.");          if (is_null($remoteName)) {             $remoteName = $source;         } else if (!is_string($remoteName)) {             throw new Exception("Remote filename must be a string, is ".gettype($remoteDir)." instead.");         }                  if (!$this->loggedIn)             $this->login();                  $data = $this->request('https://www.dropbox.com/home');         $token = $this->extractToken($data, 'https://dl-web.dropbox.com/upload');           $postdata = array('plain'=>'yes', 'file'=>'@'.$source.';filename='.$remoteName, 'dest'=>$remoteDir, 't'=>$token);         $data = $this->request('https://dl-web.dropbox.com/upload', true, $postdata);         if (strpos($data, 'HTTP/1.1 302 FOUND') === false)             throw new Exception('Upload failed!');     }          protected function login() {         $data = $this->request('https://www.dropbox.com/login');                  $data = $this->request('https://www.dropbox.com/login', true, array('login_email'=>$this->email, 'login_password'=>$this->password));                  if (stripos($data, 'location: /home') === false)             throw new Exception('Login unsuccessful.');                  $this->loggedIn = true;     }      protected function request($url, $post=false, $postData=array()) {         $ch = curl_init();         curl_setopt($ch, CURLOPT_URL, $url);         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);         switch ($this->caCertSourceType) {             case self::CACERT_SOURCE_FILE:                 curl_setopt($ch, CURLOPT_CAINFO, $this->caCertSource);                 break;             case self::CACERT_SOURCE_DIR:                 curl_setopt($ch, CURLOPT_CAPATH, $this->caCertSource);                 break;         }         curl_setopt($ch, CURLOPT_HEADER, 1);         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);         if ($post) {             curl_setopt($ch, CURLOPT_POST, $post);             curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);         }                  // Send cookies         $rawCookies = array();         foreach ($this->cookies as $k=>$v)             $rawCookies[] = "$k=$v";         $rawCookies = implode(';', $rawCookies);         curl_setopt($ch, CURLOPT_COOKIE, $rawCookies);                  $data = curl_exec($ch);                  if ($data === false)             throw new Exception('Cannot execute request: '.curl_error($ch));                  // Store received cookies         preg_match_all('/Set-Cookie: ([^=]+)=(.*?);/i', $data, $matches, PREG_SET_ORDER);         foreach ($matches as $match)             $this->cookies[$match[1]] = $match[2];                  curl_close($ch);                  return $data;     }      protected function extractToken($html, $formAction) {         if (!preg_match('/<form [^>]*'.preg_quote($formAction, '/').'[^>]*>.*?(<input [^>]*name="t" [^>]*value="(.*?)"[^>]*>).*?<\/form>/is', $html, $matches) || !isset($matches[2]))             throw new Exception("Cannot extract token! (form action=$formAction)");         return $matches[2];     }  }?>
    index.html

    codice:
    <?php require 'DropboxUploader.php'; $uploader = new DropboxUploader(email', 'pass'); $uploader->upload('d://a.txt');  ?>
    inpratica mi dice che vuole l'estensione cUrl pero non so dove includerla e dove scaricarla Aiuto!

  2. #2
    Utente di HTML.it L'avatar di danlupo
    Registrato dal
    Jul 2009
    Messaggi
    314
    Lo trovi nel file PHP.ini

    dovresti avere una riga (la mia è la 949 del file php.ini ma potrebbe essere diversa nel tuo caso) scritta in questo modo:

    codice:
    ;extension=php_curl.dll
    togli il " ; " e riavvia il tuo server locale.


    Ps. Spero tu abbia maggior fortuna mia nell'utilizzare PHP e DropBox
    Se rispondo ad una discussione è perchè so quello che dico ed ho voglia di rispondere, non per aumentare il contatore messaggi

  3. #3
    Adesso ho problemi con i certificti SSL

  4. #4
    Utente di HTML.it L'avatar di danlupo
    Registrato dal
    Jul 2009
    Messaggi
    314
    Purtroppo penso, da quel poco che ho capito, che tu possa usare dropbox e le sue api solo che stai lavorando in https quindi con certificato SSL..
    Se rispondo ad una discussione è perchè so quello che dico ed ho voglia di rispondere, non per aumentare il contatore messaggi

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.