I am trying to convert the following hardcoded pairs of data to dynamic javascript array and use that array in saver function?
i tried the following but saver function keep giving me this error:Missing files.See Documentation.so that means either i didnt save data pairs to array correctly or i didn't pass the array to saver function correctly!could any one help me fix this problem and save pairs of data to array and pass it to saver function?
Code:
files: [
{'url': '<?PHP echo $imagePath1_Value; ?>', 'filename': '1.jpg'},
{'url': '<?PHP echo $imagePath2_Value; ?>', 'filename': '2.jpg'},
{'url': '<?PHP echo $imagePath3_Value; ?>', 'filename': '3.jpg'},
],
i tried the following but saver function keep giving me this error:Missing files.See Documentation.so that means either i didnt save data pairs to array correctly or i didn't pass the array to saver function correctly!could any one help me fix this problem and save pairs of data to array and pass it to saver function?
Code:
<script type="text/javascript" src="[URL unfurl="true"]https://www.dropbox.com/static/api/2/dropins.js"[/URL] id="dropboxjs" data-app-key="xxxxxxxxxxxxxx"></script>
<script>
var i=1;
files = new Array();
function addtoArray(a,b){
alert("URL:"+a+"\nFileName:"+b);
files[i] = { url: +a, filename: +b };
i++;
};
function saver(){
var options = {
//here i want to use array i created above instead of hardcode filepath and filenames
files:[];
//files: [
//{'url': '<?PHP echo $imagePath1_Value; ?>', 'filename': '1.jpg'},
//{'url': '<?PHP echo $imagePath2_Value; ?>', 'filename': '2.jpg'},
//{'url': '<?PHP echo $imagePath3_Value; ?>', 'filename': '3.jpg'},
//],
success: function () {
// Indicate to the user that the files have been saved.
alert("Success! Files saved to your Dropbox.");
},
progress: function (progress) {},
cancel: function () {},
error:function (errorMessage) { alert("ERROR: " + errorMessage); }
};
Dropbox.save(options);
};
</script>
<body>
<button onclick="addtoArray('<?PHP echo $imagePath1_Value; ?>','1.jpg')">add to array</button>
<button onclick="addtoArray('<?PHP echo $imagePath2_Value; ?>','2.jpg')">add to array</button>
<button onclick="addtoArray('<?PHP echo $imagePath3_Value; ?>','3.jpg')">add to array</button>
<button onclick="saver()">save</button>