[development] creating a file - path problems
Jeff Greenberg
jeff at ayendesigns.com
Fri Nov 6 16:23:36 UTC 2009
andrew morton wrote:
> It's a bit of a pain to learn but you'll save yourself some headaches
> by using Drupal's file functions in includes/file.inc for doing path
> handling. If you're trying to create a file in Drupal's files
> directory use:
> file_create_path('the/desired/filename.ext');
> which give you a path relative to Drupal's root. If you need the full
> path from the server root you'll need to use PHP's realpath() which
> only works with existing files so you'll need to use:
> realpath(file_directory_path()) . 'the/desired/filename.ext';
> Once you get some data saved in there you can use file_create_url() to
> get a URL for the file that you can send out to visitors so they can
> download the file.
>
> andrew
>
>
>
When coding
realpath(file_directory_path()) . 'the/desired/filename.ext';
Isn't there an assumption that file_directory_path() is relative to the
current path? Otherwise how does realpath know where it's intended to
go? Which kind of brings me back to the original question, of
file_directory_path being relative to...what? Will my current position,
when invoking file_directory_path() always be relative to the Drupal
root, even if the current page has a path that is a subdirectory off the
Drupal root?
More information about the development
mailing list