i am interested in creating a block on my drupal site that imports an include file (.inc) from another site.

i have tried using the html include format (!--#include virtual="http://example.com/whatever.inc"--) (with brackets of course, but when i put them in they make it an html comment that is no longer viewable in the post) but this has not worked.

i also tried using a php include (include_once "http://example.com/whatever.inc";) which does import the file, however, for some reason does not display any of the actual block - no table, no label, nothing - only the contents. this certainly seems strange and i dont know if it is my command that is wrong or there is a bug.

regardless, i want to get it working one way or another. i think i would prefer to use the html way because i am guessing that using the php "include_once" is perhaps not the best (in terms of security and/or convention) thing to do.

any advice would be much appreciated.

erik.

Comments

Some options

The "HTML include" will likely not work unless you have some sort of server-side includes (SSI) turned on for parsing PHP files...

As for the PHP way...you can only include local files -- see the include_once() entry in the manual.

However, if your host has CURL installed, the curl functions might be what you are looking for. But, you still need to execute any PHP code that you retrieve...

Any reason not to store the file locally? Or retrieve the file, write it to disk temporarily, include_once() it, then delete it...

--
Boris Mann

PHP can (usually) include remote files

No, PHP can include remote files. Fom http://php.net/include:
If "URL fopen wrappers"  are enabled in PHP (which they are in the default configuration), you can specify the file to be included using an URL (via HTTP or      other supported wrapper - see Appendix I for a list of protocols) instead of a local pathname.

From http://php.net/include-once:

Windows versions of PHP prior to PHP 4.3.0 do not support accessing remote files via this function, even if allow_url_fopen is enabled.
</a>

With those caveats, include/include-once/require/require-once do support including remote files. The manual provides several examples.

thanks...

for the help.

i am creating an indymedia site and am trying to pull in the "cities list" which is the big list of all the indymedia sites. the file i am including is here: http://www.indymedia.org/local/include/cities.inc

i don't want to store the file on my site, because of course, i don't maintain the list.

you can go to my test site: http://mediamutiny.org/nbimc/ and see the cities list running down the left side. i am using include_once. so it certainly works, but the strange part is that the rest of the code for the block is not there.

if you view source you notice that the other blocks have the comment and tables, etc. while the cities list does not.

so i guess maybe the include_once is the way to go, but now to figure out the bugs...

any suggestions?

erik.

Return content, don't print it

If you are using a PHP block, make sure to return the data. If you print the data directly, Drupal will not be able to wrap a box or title around it. I guess you'll want to use PHP's output buffering to catch the output and to hand it to Drupal.

Here is some code that illustrates how this can be implemented. I haven't tested it but it should get you started:

ob_start();
include_once "foo.html";  
$output = ob_get_contents();
ob_end_clean();
return $output;

beautiful!

it works perfectly. thank you.

What should be the location for foo.html?

Hi,
Where should we store the foo.html in this case, at /var/www/html ?

SSI

"include virtual" is not HTML syntax (which has no "include"), it's an Apache SSI invocation. So make sure your Apache server is correctly configured to use it (You may have to research how to configure Apache to parse a file as both PHP and SSI at the same time.)

PHP's include() is not the "include virtual" equivalent; for that, you'd need the virtual() function .

It's hard to suggest why the PHP include did not produce the results formatted as you expected, since you're not showing what the the included & including files are. If the above two manual refs don't resolve your problem, do repost with more detail.

nobody click here