I'm trying to avoid having to create static files. I would like to submit data directly to Dropbox with AJAX.
I tried one method of adding post data to the options to the url which returns the content. This doesn't work. I didn't expect it to work, but it did get far enough to time out while sending. Perhaps a problem with headers.
The other method would be not sending a url but just supply a data stream of text but the drop-in API doesn't support this.
<?php
header('Content-Type: text/csv');
header('Content-Disposition: attachment; filename="keywords.csv"');
if (isset($_POST['csv'])) {
$csv = $_POST['csv'];
echo $csv;
}
jQuery('#kwl-export-dropbox').click(function(e) {
e.preventDefault();
var kwl_url = jQuery('#kwl-url').val() + 'kwl-cvs.php';
var results = jQuery('#kwl-results').val();
var post_data = { cvs: results };
var options = {
data: post_data,
type: 'POST',
success: function () {
console.log("Success! File saved to your Dropbox.");
},
progress: function(progress) {
console.log("Progress: " + progress);
},
cancel: function() {
console.log("Cancelled");
},
error: function(errorMessage) {
console.log("Error: " + errorMessage);
console.log("Data: " + results);
console.log("URL: " + kwl_url);
}
};
Dropbox.save(kwl_url, "keywords.csv", options);
});