[wp-hackers] Access files inside a plugin directory?

Peter van der Does peter at avirtualhome.com
Tue Mar 23 16:49:35 UTC 2010

On Mon, 22 Mar 2010 15:29:42 -0700
Jeff Rose <mirepup at gmail.com> wrote:

> Hi Everyone, sorry to interrupt, and I hope this is the correct place
> for this question.
> I have a plugin that has a data file that goes with it. Right now,
> that datafile has to be located in the site root in order for the
> plugin to access it.
> Is it possible to have that data file reside in my plugin directory,
> so the user doesn't have to upload it separately?
> On my test blog, it's throwing a 404 error with the basic
> WP .htaccess file. I have verified the correct path, and even
> attempting to access the file directly throws a 404.
> Thoughts?

Let me start by asking if this data file is being updated or modified
by the plugin and then used again.
Because if that is the case residing that data file in your plugin
directory is not a good idea.
This is because when the plugin is being updated automatically through
WordPress the plugin directory is being deleted before installing the
updated version and you will loose your data file.
If the data file is being modified and reused it is better to include
the starting data file with the plugin and within the plugin copy that
file to the upload directory if it doesn't exists there. Your plugin
can use this path.
Use wp_upload_dir( ) to get the upload directory and url.

You could create a directory under upload with your plugin name, so
it's clear why this directory exists.

To answer your 404 error, there are a few possibilities why this
1. Ownership of the data file is incorrect. The user the webserver in
running under doesn't have the right to read the file.
2. In general wrong file permissions of the file.

Peter van der Does

GPG key: E77E8E98

IRC: Ganseki on irc.freenode.net
Twitter: @petervanderdoes

WordPress Plugin Developer
Blog: http://blog.avirtualhome.com
Forums: http://forums.avirtualhome.com
Twitter: @avhsoftware

More information about the wp-hackers mailing list