Coder Social home page Coder Social logo

dropboxuploader's Introduction

Dropbox Uploader

Dropbox Uploader is a PHP class named DropboxUploader which can be used to upload files to Dropbox, an online file synchronization and backup service.

Its development was started before Dropbox released their API, and to work, it scrapes their website. So you can and probably should use their API now as it is much more stable. It's the Dropbox Core API in PHP.

You can use the Dropbox Uploader to create a file upload form for your website, which uploads files to your dropbox. The example.php is a good start; just remove the email/password/destination fields and insert the respective values.

Usage

require 'DropboxUploader.php';

$uploader = new DropboxUploader('[email protected]', 'password');
$uploader->upload('path/to/a/file.txt');

For a more complete usage example, see example.php.

License

Dropbox Uploader is licensed under the MIT License (MIT).

Troubleshooting

I'm getting the following error:

Error: Cannot execute request: SSL certificate problem, verify that the CA cert is OK.⤦
⤥ Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

This means that the certificate of the Certification Authority (CA) that Dropbox uses for their SSL certificates is not installed on your system or PHP/cURL is not configured correctly to find it.

If you ARE the system administrator, try installing the CA certificates bundle to a system-wide location. If you use a package management system, this will ensure that they are kept up to date automatically. On Debian Linux for example, you can install the package ca-certificates.

If you are NOT the system administrator, you can download just the needed certificate and point DropboxUploader to it (before calling the upload() method):

$uploader->setCaCertificateFile("/absolute/path/to/the/cacert.file");

It is also possible to do this setting in the PHP ini file for PHP 5.3.7 and above. See curl.cainfo for the ini configuration and look for the CURLOPT_CAINFO option on curl_setopt (PHP manual).

Developing

To develop, it is most easy to checkout the hakre/DropboxUploader branch:

git clone -b development git://github.com/hakre/DropboxUploader
cd DropboxUploader

Them retrieve the dependencies using Composer:

wget http://getcomposer.org/composer.phar
php composer.phar install

Testsuite

Dropbox Uploader comes with a Phpunit testsuite located in the test folder.

To get the testsuite configured, copy phpunit.xml.dist to phpunit.xml and modify the Dropbox email and password credentials and the SSL certificate store configuration (might be required if not set in PHP ini curl.cainfo).

If you want to use any of these settings from the commandline, set an environment variable with the same name. Environment variables have a higher priority than the XML configuration;

export Dropbox_Credential_Password=your-password-goes-here

You can then invoke the testsuite from the projects root directory:

vendor/bin/phpunit test

Branching

Development is done against hakre/DropboxUploader, the development branch. Create yourself a new branch from it and name it for every non-trivial changes you want to introduce.

Changes are then taken from feature branches into development and then into master.

Expect the development branch to get some force-pushes, just to keep in mind when your development branch diverges - better give your local branch a different name.

dropboxuploader's People

Contributors

hakre avatar jakajancar avatar jongotlin avatar leesto avatar mic92 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dropboxuploader's Issues

dropbox uploader was not working

For the past 4 days the dropbox uploader was not working . It was suddenly stopped. Please check this.
ERROR


Fatal error: Uncaught exception 'Exception' with message 'Upload failed!' in /home/icampuz/Backup/DropboxUploader.php:131 Stack trace: #0 /home/icampuz/Backup/dropboxBackup_ngi.php(8): DropboxUploader->upload('/home/icampuz/b...', 'backup', 'ngi_db.zip') #1 {main}

thrown in /home/icampuz/Backup/DropboxUploader.php on line 131

Great work. Would it be possible to list files in folder

You made a great work, expecially because your code allow the login to Dropbox by simply using the email and password. I would like your help to extend the functionality to list files in folder on dropbox.

Can you help me?

Not Working / Code 500 / example.php Line 27

Hello,

I am getting an error code 500 when simply try to run the example.php code on my personal website. It is hosted with Bluehost, and the error logs indicate that there is bad syntax on line 27 of the example.php, but I can't figure it out. Please provide more detailed instructions on how to use this code properly because it could be really useful!!! Do you know of code that uses the DropBox API to accomplish this type of upload?

Thanks,

David

Backups Failure on File Branch

The DB works great!

Default Database backed up successfully to BFI-2013-03-12T23-31-06 in destination Dropbox in 6598.73 ms.

The File Backup does not
Could not run backup because the file could not be saved to the destination.

They are the same destination same config.

403 Forbidden on Dropbox Upload

From today, when trying to upload to Dropbox, I'm getting a 403 Forbidden error in the response on line 130:
$data = $this->request(self::HTTPS_DROPBOX_COM_UPLOAD, $postData);

The response ($data) from that request looks like:

HTTP/1.1 100 Continue

HTTP/1.1 403 Forbidden
Server: nginx
Date: Fri, 25 Apr 2014 08:39:07 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
pragma: no-cache
cache-control: no-cache

Nothing has changed with my upload/backup script, can only assume it's a Dropbox issue or something has changed with the upload process.

File upload timestamps broken

Since ca. 2014-08-09 the dates of the files are set to the beginning of the Unix epoch 1/1/1970 (plus the offset in the account settings).

Scheduled to be fixed in one of the next versions (v1.1.19 or v1.1.20), the fix is currently in the development branch.

DropboxUploader warns about a deprecated feature on PHP 5.5

Hello there,

With error_reporting = E_ALL and display_errors = 1, DropboxUploader warns about a deprecated feature on PHP 5.5

The full message looks like this:
Deprecated function: curl_setopt(): The usage of the @filename API for file uploading is deprecated. Please use the CURLFile class instead in DropboxUploader->request() (line 125 of /xxx/drupal/sites/all/libraries/DropboxUploader/DropboxUploader.php).

Uploading the file still works, though.

Indeed, this depreciation is fully documented on the PHP website:

"CURLOPT_POSTFIELDS: The full data to post in a HTTP "POST" operation. To post a file, prepend a filename with @ and use the full path. The filetype can be explicitly specified by following the filename with the type in the format ';type=mimetype'. This parameter can either be passed as a urlencoded string like 'para1=val1&para2=val2&...' or as an array with the field name as key and field data as value. If value is an array, the Content-Type header will be set to multipart/form-data. As of PHP 5.2.0, value must be an array if files are passed to this option with the @ prefix. As of PHP 5.5.0, the @ prefix is deprecated and files can be sent using CURLFile."

(quoted from http://www.php.net/manual/en/function.curl-setopt.php)

It would be nice to fix it before PHP 5.5 becomes the mainstream version... May not happen anytime soon, I know ;)

Thanks,
Krizalys

Login unsuccessful

Since this morning, my cronjobs have returned the exception 'Login unsuccessful'. I can use the login credentials on the dropbox website, so that doesn't seem to be the case.

Has anyone else encountered this, and in that case, is there a fix for it?

Uploading 100mb++ problems

Hello,

I'm using your code to help me get video submissions from my website visitors. Thing is, when they upload 100mb+, It doesnt give you a confirmation of the upload nor the error. Is there something I can do to fix this problem? Thanks a lot!!

Regards,

Mike

Get file link

How to get file link from dropbox to my php page ?

Dropbox filesize limit

According to Dropbox Page, filesize limit through the website is set to 10Gb.
https://www.dropbox.com/help/5/en

Last filesize limit was 300Mb

When I tried to change the dropbox configuration to 10Gb, I also get the upload failed error message
const DROPBOX_UPLOAD_LIMIT_IN_BYTES = 10737418240;
Any idea about this issue ?

Reference: #9

Uploader now ignores script if file already exists

I understand how for security purposes a change like this would be necessary, but in the scenario where I was using the script, I needed the files to get overwritten. Perhaps the upload function could contain a 4th parameter for overwrite that's false by default?

Then we can easily run the upload w/ the overwrite flag without any major changes to the system. Please advise.

Caught exception: Login unsuccessful.

I am getting a very weird problem. The code works from my laptop, but it does not work on my server.
the certificate is the same. The DropBoxUploader is the same.

Any ideas?

Dropbox has a filesize limit/restriction on upload

@Tomaas reported a problem with uploading large files:

I seem to have the same issue on 1.1.7 while uploading a large file (> 300mo) after 5 minutes of upload:

Fatal error: Uncaught exception 'Exception' with message 'Upload failed!' in path/DropboxUploader.php:95
Stack trace:

0 path/downloader.php(80): DropboxUploader->upload('pathtofile', 'Downloads')

­1 {main}

thrown in path/DropboxUploader.php on line 95

@dexigner explained that there is a filesize limit of 300 MB:

Dropbox doesn't support uploading larger than 300MB (through the website, which this uploader uses)
https://www.dropbox.com/help/5/en

Error: [DropboxUploader] #268699650 Cannot extract login CSRF token.

I get this message of error when I try to login and upload a file.

private function extractTokenFromLoginForm($html) {
    $pattern = '~
        (?J)
        # HEADER cookie: set-cookie: js_csrf=JDAyWg55Y_xItHN_LB8KJ3d5; Domain=
        set-cookie:\ js_csrf=(?P<token>[A-Za-z0-9_-]+);\ Domain=

        # HTML: <input type="hidden" name="t" value="UJygzfv9DLLCS-is7cLwgG7z" />
        |<input\ type="hidden"\ name="t"\ value="(?P<token>[A-Za-z0-9_-]+)"\ />

        # JSON: , "TOKEN": "mytoken",
        |,\ "TOKEN":\ "(?P<token>[A-Za-z0-9_-]+)",\
    ~x';
    if (!preg_match($pattern, $html, $matches)) {
        throw new Exception('Cannot extract login CSRF token.', self::CODE_SCRAPING_LOGIN);
    }

    return $matches['token'];
}

I put my token on "TOKEN": "...." but it's not working, why?
thank you

DropboxUploader Still Broken

Re: #29

The work around specified seems to have broken... all it gives me now is:

Error: [Exception] #0 Login unsuccessful.

Any ideas on how to resolve?

Many thanks!

Unsuccessful Login

Hi, I'm getting an unsuccessful login suddenly? It used to work fine until a few weeks ago. I'm guessing Dropbox has changed something in its setup after issuing out the new Dropbox link with MS Office... any ideas on how to fix it?

I am using Version bump v1.1.22 of the uploader.

Thanks

Exception: Cannot extract login CSRF token.

I think Dropbox may have changed the way they handle login. Since a few days, running phpunit tests returns this:

ESSSS.

Time: 1.81 seconds, Memory: 3.75Mb

There was 1 error:

1) DropboxIntegrationTest::testLogin
Exception: Cannot extract login CSRF token.

/Users/clement/Desktop/DropboxUploader/DropboxUploader.php:260
/Users/clement/Desktop/DropboxUploader/DropboxUploader.php:179
/Users/clement/Desktop/DropboxUploader/test/integration/DropboxIntegrationTest.php:39
phar:///usr/local/bin/phpunit/phpunit/TextUI/Command.php:186
phar:///usr/local/bin/phpunit/phpunit/TextUI/Command.php:138

FAILURES!
Tests: 3, Assertions: 10, Errors: 1, Skipped: 4.

Error: [DropboxUploader] #268698113 Login unsuccessful.

I was using version 1.12 and started getting the error. I am now using the latest 1.19 version and still get the error. I am using example.php. With the same username and password I can log in directly on dropbox website

Remove version number in files

I think the version number should be removed from composer.json and DropboxUploader.php. Lets just have the version bump when you make a new tag for packagist.

Using Dropbox Uploader to upload a file from FTP to Dropbox

Hi, first of all thanks for this amazing project.

My issue:

Dropbox uploader can upload a file from local directory to dropbox. My question is, how can I use it to upload a file from FTP server to Dropbox?

For example: I have a file "backup.zip" in an FTP directory . So how can upload that file to Dropbox using FTP credentials.

I know I have to do this using cURL by editing function "request() " in DropboxUploader.php but I'm unable to do that. Please help...

Getting an unsuccessfull Login

I know the login works as I can go to the webpage enter the credentials and have no issue.
I am using the files as is and I get this message. Any reason why?

Unable to login

I keep getting this error message when using the script.

CODE

$uploader = new DropboxUploader('removed', 'removed');
$uploader->upload(date('Ymd').".tar.gz");

ERROR

PHP Fatal error: Uncaught exception 'Exception' with message 'Cannot execute request: Empty reply from server' in /var/www/html/DropboxUploader.php:138
Stack trace:
#0 /var/www/html/DropboxUploader.php(90): DropboxUploader->request('https://dl-web....', true, Array)
#1 /var/www/html/DropboxUploader.php(166): DropboxUploader->upload('20121126.tar.gz')
#2 {main}

thrown in /var/www/html/DropboxUploader.php on line 138

Gateway Timeout

I am getting below error while uploading multiple files at same time

{
"fault": {
"faultstring": "Gateway Timeout",
"detail": {
"errorcode": "messaging.adaptors.http.flow.GatewayTimeout"
}
}
}

It uploads almost 4 files but not all files

DropboxUploader No Longer Working

It would appear that Dropbox.com has changed its login system and no longer uses the hidden "t" token tag anymore. This has unfortunately stopped the script from allowing me to login.
Taking a look at the new page source, it would appear it was a deliberate attempt to stop scripts like DropboxUploader from function.
I'll keep trying to find a way around the new changes and post any success I have. Hopefully someone else might noticed something I've overlooked that allows the script to function correctly.

Echo The Path of The Uplaoded File On Success

Hi, How can I echo (print) the file path on success?

echo 'File successfully uploaded to your Dropbox!';

I tried adding " echo $_FILES['file']['name'] " after closing span:

echo 'File successfully uploaded to your Dropbox!' . echo $_FILES['file']['name'];

but it didn't work, for now I want just to echo of the uploaded file, I will add
" https://dl.dropboxusercontent.com/u/< USER ID>/'.
later because I want it for a project that's means I wont change the user id
thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.