How to include images with path name?
I would like to have users include various images in pages, or the body of other content types. They are accustomed to coding html images and links, with the various options for the images (align left, center, etc).
The problem is, I seem to have to code the entire path name of the image in the html:
This is very awkward - when I move content from a test site to production, or from one site to another, I would need to find all these links somehow and recode them. There could be hundreds of them:(
Looking through various posts, I see that one can use php code to do this:
<?php
global $base_url;
?>OK, this works, but it means I now need to enable php code in the Input Format for these content types. Isn't this supposed to be dangerous? I would like not to have users entering php code into their content.
Shouldn't the html be looking for files relative to some root position? I would expect something like the following to work, where the file is referenced relative to some root directory:
However, I can't seem to find anything that works.
My Apache Document Root is currently set to (test system)
C:/Program Files/Apache Software Foundation/Apache2.2/htdocs
and my test drupal installation is under this in asras1.
C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/asras1
which puts sites, etc underneath:
C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/asras1/sites/default/files
Surely someone has a better way to do this than putting php code in generic user posts?
Thanks,
brew

Code correction
Oops, I didn't put code tags in.
The fully specified html that works is:
<img src="/asras1/sites/default/files/images/Image1.jpg" />The php code that works is
<img src="<?php echo $base_url; ?>sites/default/files/images/Image1.jpg" />However, I would like to avoid the php code, and code the images relative to some base root directory, something like
<img src="sites/default/files/images/Image1.jpg" /><img src="files/images/Image1.jpg" />or something similar. However, I just can't find a combination of directories that works.
Thanks for any help,
brew
For full portability, no,
For full portability, no, you cannot avoid PHP that will correct your path. Page content can be displayed under any URL, so the code has to correct for that.
Recommended syntax is:
<img src="<?php echo url('relative/path/image.jpg'); ?>" />Because just prepending $base_url has other limitations.
There is an extra File API help if you are referring to Drupal '/files/' directory, and another one that you can use to represent '/path/to/current/theme' also - which you should choose to use when appropriate. Not vital if you are never going to move or upgrade your site, but best-practice if you can.
Keep looking at examples of how other modules do it.
.dan.
if you are asking a question you think should be documented, please provide a link to the handbook where you think the answer should be found.
| http://www.coders.co.nz/ |
How about reptags?
Dman's approach looks good for what I write, but I am nervous about letting users write php code in their submissions.
One, it seems like a dangerous thing, and
two, they don't know php. They find that writing
Yes, php is NOT on for
Yes, php is NOT on for common users.
have a look at pathologic
.dan.
if you are asking a question you think should be documented, please provide a link to the handbook where you think the answer should be found.
| http://www.coders.co.nz/ |