[support] path problem

Victor Kane victorkane at gmail.com
Sun Aug 3 11:06:59 UTC 2008


ok, John, you have to understand the difference between URLs, on the one
hand, and file system paths, on the other.

When you are generating a path for an image, say a logo, in order to specify
a SRC attribute, that path must be a URL for apache to use and not a file
system path. In other words, either "
http://example.com/sites/all/themes/my_theme/images/cool_logo.png", or a
relative URL (relative to the Drupal document root)
"/sites/all/themes/my_theme/images/cool_logo.png".

This is complicated by the fact that for CSS, a background image would be:

#mission {
  background transparent url(images/background.png);
}

Now, let's say you need to get the file system path to an image in order to
open it up and get its properties, however, like width and height, because
you want to make a thumbnail on the fly.

The following works for me. Assuming I open up an image node and can access
its $file -> filepath property. The absolute path can be attained like this:

          $filedir = realpath('.') . '/' . $file -> filepath;
          $info = image_get_info($filedir);

That works for me, perhaps someone has a better way of doing this.

The relative file system path woujld be your "opendir(files/path_to_image)",
which works in many cases (all?). The reason it works is because the current
directory is the Drupal document root (is where PHP is executing normally),
so my absolute path above depends on this (realpath(".")) as does your
relative path.

Perhaps the best lesson is, if it works for you, use it. But you must
understand the difference between URLs and functions which return URLs, and
file system paths, and functions which return these.

Victor Kane
http://awebfactory.com.ar




On Sat, Aug 2, 2008 at 11:20 PM, John Horning <john at rivul.com> wrote:

>  For some reason this works from deeper directory levels:
> opendir("files/");
> but this doesn't: opendir(base_path() ."files/");
>
> Is this a misapplication?
>
>
>
> Victor Kane wrote:
>
> Well, assuming you are talking about URLs, you should be all set. All
> Drupal modules see the world from the Drupal document root, so <?php
> base_path() . 'files' ?> should be fine for a URL.
>
> What is it you cannot get done?
>
> On Sat, Aug 2, 2008 at 1:01 PM, John Horning <john at rivul.com> wrote:
>
>>  Do you know anything about file_directory_path()?  It returns "files",
>> which is correct for use from the home directory, but not useful on other
>> levels.
>>
>>
>> John Horning wrote:
>>
>> I can't get anything other than "/" returned by base_path(), regardless of
>> the level I'm on.  I must be missing something.
>>
>>
>> Victor Kane wrote:
>>
>> As URL?
>>
>> Assuming it were ./files, then try sthg like <?php base_path() . 'files'
>> ?>
>>
>> On Sat, Aug 2, 2008 at 9:15 AM, John Horning <john at rivul.com> wrote:
>>
>>>  Thanks.  Is there something like that to get me to the files directory?
>>> John
>>>
>>> Victor Kane wrote:
>>>
>>>  Try the following:
>>>
>>> <?php base_path() . path_to_theme() ?>/box_bottom.png
>>>
>>> <img src="<?php print base_path() . path_to_theme() . "/pic/mary.png";
>>> ?>" />
>>>
>>> Victor Kane
>>> http://awebfactory.com.ar
>>>
>>> On Fri, Aug 1, 2008 at 10:28 PM, John Horning <john at rivul.com> wrote:
>>>
>>>> Apparently Drupal does not allow you to reference absolute URL paths in
>>>> scripts, which is causing me a problem.  I have a script in my page.tpl.php
>>>> that randomly picks images from a directory and displays them in the
>>>> header.  This works when you're on the top level, but not below since I'm
>>>> using a relative path to get to the image directory.  Can anyone tell me the
>>>> proper way of doing this?
>>>>
>>>> --
>>>> [ Drupal support list | http://lists.drupal.org/ ]
>>>>
>>>
>>>   No virus found in this incoming message.
>>> Checked by AVG - http://www.avg.com
>>> Version: 8.0.138 / Virus Database: 270.5.10/1585 - Release Date: 8/1/2008 6:39 AM
>>>
>>>
>>>
>>> --
>>> [ Drupal support list | http://lists.drupal.org/ ]
>>>
>>
>>  No virus found in this incoming message.
>> Checked by AVG - http://www.avg.com
>> Version: 8.0.138 / Virus Database: 270.5.10/1586 - Release Date: 8/1/2008 6:59 PM
>>
>>
>>  No virus found in this incoming message.
>> Checked by AVG - http://www.avg.com
>> Version: 8.0.138 / Virus Database: 270.5.10/1586 - Release Date: 8/1/2008 6:59 PM
>>
>>
>>
>> --
>> [ Drupal support list | http://lists.drupal.org/ ]
>>
>
>  No virus found in this incoming message.
> Checked by AVG - http://www.avg.com
> Version: 8.0.138 / Virus Database: 270.5.10/1586 - Release Date: 8/1/2008 6:59 PM
>
>
>
> --
> [ Drupal support list | http://lists.drupal.org/ ]
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/support/attachments/20080803/11562c86/attachment.htm 


More information about the support mailing list