Support » Plugin: WordPress Backup to Dropbox » How to tweak this plugin for PHP 7

  • Hey all– as some have noted, this plugin doesn’t work under PHP 7. Typically it complains that it’s having trouble uploading to Dropbox, and logs show a bad Dropbox API with an unexpected “overwrite” parameter.

    Presumably the author will update this sooner or later; for the time being, here’s a quick source code tweak that made it work for me. All paths are relative to $YOUR_SITE_DIRECTORY/wp-content/plugins/wordpress-backup-to-dropbox.

    In file Dropbox/Dropbox/OAuth/Consumer/Curl.php: comment out the line:
    $options[CURLOPT_SAFE_UPLOAD] = false;
    (this option is no longer valid in PHP 7)

    In file Dropbox/Dropbox/OAuth/Consumer/ConsumerAbstract.php: replace the test if (isset($value[0]) && $value[0] === '@') with if ($value instanceof CURLFile)

    In file Dropbox/Dropbox/API.php: replace 'file' => '@' . str_replace('\\', '/', $file) . ';filename=' . $filename with 'file' => new CURLFile(str_replace('\\', '/', $file), "application/octet-stream", $filename)

    This replaces the long-deprecated, now-disabled support for uploading files with “@/file/to/upload” with the replacement “CURLFile” class. Also a note to the author (and optional patch for the reader): check the return value for curl_setopt_array, as this was failing unnoticed, leading to confusing behaviour downstream.

Viewing 14 replies - 1 through 14 (of 14 total)
  • jhtjards


    Thanks a lot, that worked in PHP 7.1!

    Apologies for the noob question but can you use this on the plugin zip file and then upload it? Also how do you check the return value?

    Yeah if you’ve got some scheme like you have to upload a zip and then the server unpacks it for you? Then it should suffice to unzip, make the tweaks, zip back up and upload.

    Checking curl_setopt_array is like:

    if(curl_setopt_array(/* arguments here */) === FALSE)
    die(“curl_setopt_array failed!”);

    See also which describes the function and its error behaviour

    Thanks for that, I’m a scripting novice so any help on how I should set up the check with reference to Dropbox etc would be amazing. I had a look at the link and it didn’t make sense to me in terms of items that could be causing the script to fail.

    • This reply was modified 6 months, 2 weeks ago by  charliejustus.

    Not sure what you mean by setting up the check? Could you elaborate a bit?

    You wrote the code that had the section /* arguments here */

    I was wondering what arguments I would need to be putting in there to check everything is running as it should be.

    Ah I see, those are the existing arguments to the call– in the source for wpb2d, in the existing file Dropbox/Dropbox/OAuth/Consumer/Curl.php we see:

    curl_setopt_array($handle, $options);

    That call is unchecked, in that its return value is discarded (ignored). A checked equivalent is:

    if(curl_setopt_array($handle, $options) === FALSE)
      throw new Exception("curl_setopt_array failed!");

    So we have kept the same arguments (inputs) the original call, $handle, $options, but wrapped it in the if(... === FALSE) test that determines whether it succeeded or not. In the existing wpb2d code, with PHP 7 it was failing due to an invalid argument, but that was going un-noticed because this check was missing. With the check in place, we will get an explicit message if it fails.

    • This reply was modified 6 months, 2 weeks ago by  smowton.

    Ah cool! So do I need to go through all of the php for unchecked items? Or is that the one that seems to giving the most problems.

    There is just this one call in wpb2d– every function that wants to make a Dropbox API request delegates to this function, so there is only one site where the change is necessary.

    Outstanding! Thank you so much for walking me through that.

    Hi Guys,

    I’m getting this error message when I upload the amended plugin folder. I can’t understand why i’m getting this error as everything looks right to me.

    Parse error: syntax error, unexpected ”overwrite” (T_CONSTANT_ENCAPSED_STRING), expecting ‘)’ in /home/mawebfaction/webapps/naked/wp-content/plugins/wordpress-backup-to-dropbox/Dropbox/Dropbox/API.php on line 108

    This is the entire section. Is there anything out of place?

    public function putFile($file, $filename = false, $path = ”, $overwrite = true)
    if (file_exists($file)) {
    if (filesize($file) <= 157286400) {
    $call = ‘files/’ . $this->root . ‘/’ . $this->encodePath($path);
    // If no filename is provided we’ll use the original filename
    $filename = (is_string($filename)) ? $filename : basename($file);
    $params = array(
    ‘filename’ => $filename,
    ‘file’ => new CURLFile(str_replace(‘\\’, ‘/’, $file), “application/octet-stream”, $filename)
    ‘overwrite’ => (int) $overwrite,

    return $this->fetch(‘POST’, self::CONTENT_URL, $call, $params);

    throw new Exception(‘File exceeds 150MB upload limit’);

    Missing comma after “$filename)” (immediately before ‘overwrite’ => …)

    Thanks man!

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘How to tweak this plugin for PHP 7’ is closed to new replies.