1

I've an iframe in my custom drupal 7 module whihch is displaying data from a remote url like this:-

$element[$delta]['#markup'] = '<iframe class="page_flipper" src="someURL"></iframe>';

It is working well but I want to display the output of another script/program in this iframe. The program has combined code of HTML,CSS,JavaScript and PHP. In other words I want to integrate that program in the above iframe. Can anybody tell how can I do this?

I've tried to point to the program using relative path in the src attribute of the iframe like this:-

$element[$delta]['#markup'] = '<iframe class="page_flipper" src="mydir/index.php"></iframe>';

but it didn't work and drupal displays this error in the iframe "The requested page "/<site_name>/node/myFlip/index.php" could not be found. Any help is appreciated. Thanks

3
  • what happens when you use the absolute path instead of the relative path? seems like that should fix the issue Commented Oct 3, 2012 at 18:29
  • When I try to use absolute path using DOCUMENT_ROOT, the same error appears. It looks like drupal look for the index.php in some "node" directory not in the current module directory as the error above reflects. Commented Oct 4, 2012 at 4:51
  • I missed the whole part about it being a custom module and was thinking you were dealing with a script that was outside of teh drupal root. See my answer below, it's along the same lines as what Amar proposed. Commented Oct 4, 2012 at 17:07

2 Answers 2

1

Should the snippet below do the trick?

// Get the path to the module..
$module_path = drupal_get_path('module', 'MY_MODULE');

// Prepend with the Drupal root..
$path = DRUPAL_ROOT . '/' . $module_path . '/mydir/index.php'; 

// Use..
$element[$delta]['#markup'] = 
  "<iframe class='page_flipper' src='$path'></iframe>";

Safer to put the folder with the PHP script in the root of your Drupal installation, I feel. Then you can just access it with:

global $base_url;
$path = $base_url . '/ext/index.php';
Sign up to request clarification or add additional context in comments.

Comments

1

You can use Drupals drupal_get_path() and url() functions to build an absolute url to the file.

$iframe_url = url(drupal_get_path('module','MYMODULE').'/mydir/index.php',array('absolute'=>true));

$element[$delta]['#markup'] = "<iframe class='page_flipper' src='$iframe_url'></iframe>";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.