1

I have a txt file on my Dropbox account.

My webpage is hosted on a server and I can not upload files to it from home.

But I would like to insert some informations on my webpage and so I decided to write these notes on a txt file and upload it to my Dropbox.

Now, the problem is:

  • how to insert the txt file contents into my html file so that when I update the txt file simply using Dropbox, the webpage is also update?**

I have the file index.html and I tried to insert on it the tag

<?php file_get_contents("<address to my Dropbox file>"); ?> 

which I found on other posts here. But nothing happens.

Sigur
  • 355
  • 8
  • 19

2 Answers2

2

You need to share the file and get the public URL of it, and then use this url in the get call using jquery. Take a look on this example from the Jquery.get documentation :

<div id="result"></div>
...

$.get('https://dl.dropbox.com/u/8032011/share/greetings.txt', function(data) {
  $('#result').html(data);
  alert('Load was performed.');
});

This link explains the use of public folder on dropbox : https://www.dropbox.com/help/16/en

hamilton.lima
  • 1,902
  • 18
  • 29
  • May I use the tag `` does not work. – Sigur Apr 07 '13 at 16:28
  • Should I install something related to `Jquery`? I am only using my local apache server on my Linux machine. – Sigur Apr 07 '13 at 16:38
  • 1
    take a look on this one : http://stackoverflow.com/questions/1458349/installing-jquery – hamilton.lima Apr 07 '13 at 22:03
  • It is working now. So I have to decide to use `php` or `html`. Since all my webpage was created in `html` I guess that I'll simply use your example to show the `txt` content on my page. Thanks. – Sigur Apr 08 '13 at 00:53
  • 1
    take a look on this full example : https://github.com/hamilton-lima/javascript-samples/blob/master/jquery/le_arquivo_do_dropbox.html – hamilton.lima Apr 08 '13 at 02:43
  • The last question: Is it possible to reload the `html` page automatically when the Dropbox file is updated? So people don't need to press F5. – Sigur Apr 08 '13 at 14:30
  • 1
    for that you would need to keep loading the file or have another file with the last update :) – hamilton.lima Apr 08 '13 at 15:21
1

You can't run PHP scripts in HTML files, if your server supports PHP then change your file's extension to ".php" and that code will work.
Otherwise (if you absolutely can't use PHP) you can still make this work by using embeded javascript/jquery code that will load the dropbox file to your HTML page.

Abdulaziz
  • 2,201
  • 1
  • 21
  • 35
  • Thanks. I created now a `php` file with only this: `` How to use it on my `html` file? – Sigur Apr 07 '13 at 16:48
  • 1
    @Sigur You don't use the php file like that, I would recommend renaming `index.html` file to `index.php` , then you can simply use `file_get_contents()` function inside the HTML tag you want to fill in with dropbox data(exactly like you did in your original question.) – Abdulaziz Apr 07 '13 at 16:53
  • If I use some css style it could affect the result? I don't know why but on a single `html` file with the code, everything is OK. But if I put the code on my file, nothing happens. – Sigur Apr 08 '13 at 01:31
  • by code, did you mean CSS? anyway, I really don't think CSS has anything to do with your PHP code; unless you've done something wrong, which could be easily spotted if you edit your original question and put the whole `index.php` file here so we can see what's really going on. – Abdulaziz Apr 08 '13 at 17:39