/**
  * Open file and return file pointer
  *
  * @param  string $path file path
  * @param string $mode
  * @return false|resource
  * @internal param bool $write open file for writing
  * @author Dmitry (dio) Levashov
  */
 protected function _fopen($path, $mode = 'rb')
 {
     if ($mode == 'rb' || $mode == 'r') {
         try {
             $res = $this->dropbox->media($path);
             $url = parse_url($res['url']);
             $fp = stream_socket_client('ssl://' . $url['host'] . ':443');
             fputs($fp, "GET {$url['path']} HTTP/1.0\r\n");
             fputs($fp, "Host: {$url['host']}\r\n");
             fputs($fp, "\r\n");
             while (trim(fgets($fp)) !== '') {
             }
             return $fp;
         } catch (Dropbox_Exception $e) {
             return false;
         }
     }
     if ($this->tmp) {
         $contents = $this->_getContents($path);
         if ($contents === false) {
             return false;
         }
         if ($local = $this->getTempFile($path)) {
             if (file_put_contents($local, $contents, LOCK_EX) !== false) {
                 return fopen($local, $mode);
             }
         }
     }
     return false;
 }