コード例 #1
0
 /**
  * Returns cryptographically strong secure random bytes (as a PHP string).
  *
  * @param int $numBytes
  *                      The number of bytes of random data to return.
  *
  * @return string
  */
 public static function getRandomBytes($numBytes)
 {
     Dropbox_Checker::argIntPositive("numBytes", $numBytes);
     // openssl_random_pseudo_bytes had some issues prior to PHP 5.3.4
     if (function_exists('openssl_random_pseudo_bytes') && version_compare(PHP_VERSION, '5.3.4') >= 0) {
         $s = openssl_random_pseudo_bytes($numBytes, $isCryptoStrong);
         if ($isCryptoStrong) {
             return $s;
         }
     }
     if (function_exists('mcrypt_create_iv')) {
         return mcrypt_create_iv($numBytes);
     }
     // Hopefully the above two options cover all our users.  But if not, there are
     // other platform-specific options we could add.
     throw new Exception("no suitable random number source available");
 }
コード例 #2
0
ファイル: Client.php プロジェクト: onedaylabs/onedaylabs.com
 /**
  * Creates a file on Dropbox, using the data from $inStream as the file contents.
  *
  * This version of <code>uploadFile</code> splits uploads the file ~4MB chunks at a time and
  * will retry a few times if one chunk fails to upload.  Uses {@link chunkedUploadStart()},
  * {@link chunkedUploadContinue()}, and {@link chunkedUploadFinish()}.
  *
  * @param string $path
  *                     The Dropbox path to save the file to (UTF-8).
  *
  * @param Dropbox_WriteMode $writeMode
  *                                     What to do if there's already a file at the given path.
  *
  * @param resource $inStream
  *                           The data to use for the file contents.
  *
  * @param int|null $numBytes
  *                           The number of bytes available from $inStream.
  *                           You can pass in <code>null</code> if you don't know.
  *
  * @param int|null $chunkSize
  *                            The number of bytes to upload in each chunk.  You can omit this (or pass in
  *                            <code>null</code> and the library will use a reasonable default.
  *
  * @return mixed
  *               The <a href="https://www.dropbox.com/developers/core/docs#metadata-details>metadata
  *               object</a> for the newly-added file.
  *
  * @throws Dropbox_Exception
  */
 public function uploadFileChunked($path, $writeMode, $inStream, $numBytes = null, $chunkSize = null)
 {
     if ($chunkSize === null) {
         $chunkSize = self::$DEFAULT_CHUNK_SIZE;
     }
     Dropbox_Path::checkArgNonRoot("path", $path);
     Dropbox_WriteMode::checkArg("writeMode", $writeMode);
     Dropbox_Checker::argResource("inStream", $inStream);
     Dropbox_Checker::argNatOrNull("numBytes", $numBytes);
     Dropbox_Checker::argIntPositive("chunkSize", $chunkSize);
     return $this->_uploadFileChunked($path, $writeMode, $inStream, $numBytes, $chunkSize);
 }