dropbox-php-sdk
dropbox-php-sdk copied to clipboard
Check if file exists
The "best" method I've found so far is to try to get the file's metadata, which will throw an exception if the file does not exist, but of course there are more reasons why an exception may be thrown so I check the code of the exception for the 'not found' code. This was achieved by trial and error so I'm not convinced it's the best way.
try {
$meta = $dropbox->getMetadata($filename);
} catch (Exception $ex) {
if ($ex->getCode() == 409) {
// .. file does not exist
} else {
throw $ex; // re-throw any other exception
}
}
Yes, it's horrible :)