/** * Check if the given file can be uploaded from the dropbox. * * @throws Dropbox_Exception * @return string Validated path to the file */ function dropbox_validate_file($fileName) { $dropboxDir = dropbox_get_files_dir_path(); $filePath = $dropboxDir . DIRECTORY_SEPARATOR . $fileName; $realFilePath = realpath($filePath); // Ensure the path is actually within the dropbox files dir. if (!$realFilePath || strpos($realFilePath, $dropboxDir . DIRECTORY_SEPARATOR) !== 0) { throw new Dropbox_Exception(__('The given path is invalid.')); } if (!file_exists($realFilePath)) { throw new Dropbox_Exception(__('The file "%s" does not exist or is not readable.', $fileName)); } if (!is_readable($realFilePath)) { throw new Dropbox_Exception(__('The file "%s" is not readable.', $fileName)); } return $realFilePath; }
<?php if (!dropbox_can_access_files_dir()) { ?> <p class="dropbox-alert error"><?php echo __('The Dropbox files directory must be both readable and writable.'); ?> </p> <?php } else { ?> <?php $fileNames = dropbox_dir_list(dropbox_get_files_dir_path()); ?> <?php if (!$fileNames) { ?> <p><strong><?php echo __('No files have been uploaded to the dropbox.'); ?> </strong></p> <?php } else { ?> <script type="text/javascript"> function dropboxSelectAllCheckboxes(checked) { jQuery('#dropbox-file-checkboxes tr:visible input').each(function() { this.checked = checked; }); jQuery('#dropbox-file-checkboxes').trigger('dropbox-all-toggled'); }