PHP Remotely delete files on Dropbox using PHP without using an API

自古美人都是妖i 提交于 2019-12-08 13:02:47

问题


I have the code below to upload files to Dropbox. Now I'd like to modify the code below to delete certain folders / images on dropbox in a particular folder.

<?php
$siteroot = $folder_output; 

$dropbox_email='xxx@xxxxx.com';  //Dropbox username
$dropbox_pass='xxxxxxxxxxxx';   // Dropbox password

include("DropboxUploader.php");

$uploader = new DropboxUploader($dropbox_email, $dropbox_pass);

function FolderToDropbox($dir, $dropbox_link){
    global $foldername;    
    $dropbox_folder = 'Public/';
    $files = scandir($dir);
    foreach($files as $item){
        if($item != '.' && $item != '..'){
            if(is_dir($dir.'/'.$item)) FolderToDropbox($dir.'/'.$item,$dropbox_link);
            else if(is_file($dir.'/'.$item)) {
                $clean_dir = str_replace("temp_images/".$foldername."/output/", "", $dir);
                $dropbox_link->upload($dir.'/'.$item,$dropbox_folder.$clean_dir.'/');  
            } 
        }
    }
}

FolderToDropbox($siteroot,$uploader);

echo 'Copying to Cloud - Success!<br />';


?>

Without using an API(just for the sake of trying new things) could I delete certain pictures on my Dropbox.

I tried this code:

<?php
ini_set('display_errors',1); error_reporting(E_ALL);

$siteroot = $folder_output; 

$dropbox_email='xxxx@xxxxxxx.com';  //Dropbox username
$dropbox_pass='xxxxxxxxxxxxxxxxx';   // Dropbox password

include("DropboxUploader.php");

$uploader = new DropboxUploader($dropbox_email, $dropbox_pass);

function FolderToDropbox($dir, $dropbox_link){
    global $foldername;    
    $dropbox_folder = 'Public/';
    $files = scandir($dir);
    $dropbox_link->delete($dir.,$dropbox_folder.'/');  
            } 
        }
    }
}
 FolderToDropbox($siteroot,$uploader);
echo 'Copying to Cloud - Success!<br />';

?>

No errors and ntohing happens


回答1:


You have an extra comma and double //. Maybe this might make it work:

$dropbox_link->delete($dir.$dropbox_folder);  


来源:https://stackoverflow.com/questions/19483881/php-remotely-delete-files-on-dropbox-using-php-without-using-an-api

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!