Title: How add external data file
Last modified: August 21, 2016

---

# How add external data file

 *  [DrMosko](https://wordpress.org/support/users/drmosko/)
 * (@drmosko)
 * [12 years, 6 months ago](https://wordpress.org/support/topic/how-add-external-data-file/)
 * hello all,
    Im dev a plugin and need to somehow include a file from external 
   server (*.dat) , the file is updated every month. and i dont want to release 
   an update vesion every month. thank u

Viewing 9 replies - 1 through 9 (of 9 total)

 *  [chrismichaels84](https://wordpress.org/support/users/chrismichaels84/)
 * (@chrismichaels84)
 * [12 years, 6 months ago](https://wordpress.org/support/topic/how-add-external-data-file/#post-4274935)
 * As long as allow_url_fopen is enabled in php.ini you can use remote files basically
   the same way you use local files. The PHP manual talks about it here: [http://php.net/manual/en/features.remote-files.php](http://php.net/manual/en/features.remote-files.php).
 * In your case, you would probably want to use the fopen() php function to load
   the .dat file into a variable and then do whatever you need to with the data.
   The documentation for that is: [http://php.net/manual/en/function.fopen.php](http://php.net/manual/en/function.fopen.php).
 * If you were more specific about what you need, I could give you some example 
   code with some security measures. What do you want to do with the file?
 * Another good overview is [http://phpprogramming.wordpress.com/2007/02/17/using-remote-files-in-php/](http://phpprogramming.wordpress.com/2007/02/17/using-remote-files-in-php/)
 * But be warned that this can cause some serious security problems, so you should
   ONLY do this with files and servers you ABSOLUTELY trust. This may be disabled
   on shared hosting, depending.
 * I do not know of a wordpress specific function that will do this. I’d like to
   know if there is one. Anyone else want to weigh in?
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [12 years, 6 months ago](https://wordpress.org/support/topic/how-add-external-data-file/#post-4274941)
 * If the file is available through HTTP, use the [HTTP API](http://codex.wordpress.org/HTTP_API).
 *  Thread Starter [DrMosko](https://wordpress.org/support/users/drmosko/)
 * (@drmosko)
 * [12 years, 6 months ago](https://wordpress.org/support/topic/how-add-external-data-file/#post-4274942)
 * ok thank u
    I change the request and want to download the file auto every month,
   how do i do that?
 *  [chrismichaels84](https://wordpress.org/support/users/chrismichaels84/)
 * (@chrismichaels84)
 * [12 years, 6 months ago](https://wordpress.org/support/topic/how-add-external-data-file/#post-4274964)
 * For that, you use WP Chron. The API is pretty simple: [http://codex.wordpress.org/Function_Reference/wp_schedule_event](http://codex.wordpress.org/Function_Reference/wp_schedule_event)
 * But you can only go up to daily, not monthly. If that’s a problem, then the other
   option is to create a simple plugin that adds a link under an admin menu to execute
   the update and download. Then YOU fire it once a month.
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [12 years, 6 months ago](https://wordpress.org/support/topic/how-add-external-data-file/#post-4274973)
 * OR
    Schedule a daily event that checks a timestamp stored in options the last
   time the file was downloaded. If a month has passed, do it again, otherwise do
   nothing.
 * OR (there’s probably even more possibilities)
    Use crontab at the server level
   to execute a monthly task. This is identical to manually clicking a link once
   a month, except once it’s setup, you do nothing yourself.
 *  Thread Starter [DrMosko](https://wordpress.org/support/users/drmosko/)
 * (@drmosko)
 * [12 years, 6 months ago](https://wordpress.org/support/topic/how-add-external-data-file/#post-4274999)
 * can u give me simple code on how to download a remote file and overwrite existing
   one monthly?
 *  Thread Starter [DrMosko](https://wordpress.org/support/users/drmosko/)
 * (@drmosko)
 * [12 years, 6 months ago](https://wordpress.org/support/topic/how-add-external-data-file/#post-4275069)
 * hello bcworkz,
    “Schedule a daily event that checks a timestamp stored in options
   the last time the file was downloaded. If a month has passed, do it again, otherwise
   do nothing.”
 *     ```
       $nextUpdate = $options['lastUpdate']+180 ;
   
       if ( $nextUpdate < $userTime ){
   
       		// set last update
       		$options['lastUpdate'] = $nextUpdate;
       }
       ```
   
 * usertime is current timstamp
    nextupdate is timstamp options -lastupdate is timstamp
   also that created when the plugin activated. something is missing, cause the 
   increment only happening once time, and not every refresh of the page.
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [12 years, 6 months ago](https://wordpress.org/support/topic/how-add-external-data-file/#post-4275077)
 * Hi drmosko,
    I saw your other post about this as well, though I didn’t at the
   time realize it was related to your file update scheme. As your code is out of
   context, even knowing the purpose, I’m not sure what’s going on. In particular
   where is the option value coming from and how is it being saved? It sounds like
   the updated value is not getting saved for some reason.
 *  Thread Starter [DrMosko](https://wordpress.org/support/users/drmosko/)
 * (@drmosko)
 * [12 years, 6 months ago](https://wordpress.org/support/topic/how-add-external-data-file/#post-4275085)
 * I fixed it, thank all u

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘How add external data file’ is closed to new replies.

## Tags

 * [external server](https://wordpress.org/support/topic-tag/external-server/)
 * [plugin-development](https://wordpress.org/support/topic-tag/plugin-development/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 9 replies
 * 3 participants
 * Last reply from: [DrMosko](https://wordpress.org/support/users/drmosko/)
 * Last activity: [12 years, 6 months ago](https://wordpress.org/support/topic/how-add-external-data-file/#post-4275085)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
