Using drupal 6.4
What I want to achieve: having a PHP output in a block. I stored a PHP script in sites/all/default/files. This PHP script generates a html output. In admin/build/block I add a block and typed include('.all/default/files/myfile.php'); The site is in all/themes/mysite. When I saved the block the website crashed, got a Forbidden message and I had to delete the block from DB.
It should be possible to have this output in a block, but obviously I don't follow the right steps. How should this be done?

Comments

marcvangend’s picture

I assume the problem is in the path to your php file: .all/default/files/myfile.php can never be right, it should at least be ./all/default/files/myfile.php. But even then: your site is not in all/themes/mysite; that's just where your theme is. Your site is, put simply, in the site root '/'. I think you should try to include /sites/all/default/files/myfile.php (note the starting slash).

You may also want to wrap the include in an if statement that checks if the file exists at all, to prevent crashes:

<?php
$file = 'myfile.php';
if(file_exists($file)) {
    include($file);
}
?>
dman’s picture

good advice x3.

.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/ |

daddydo’s picture

marc - problem solved thanks to your suggestion.
dman - you're right. next time better!

BTW Is there a way to call a certain block in a sidebar using URL?

marcvangend’s picture

>> BTW Is there a way to call a certain block in a sidebar using URL?
What do you mean? Blocks don't have a url, you can't call them by url. Blocks are placed in a region. Displaying of a block can depend on the url of the page it is on.

dman’s picture

you might be looking for (drupal 5, the 'delta' indexes changed in D6)

print theme('block', (object)module_invoke($modulename, 'block', 'view', $delta))

eg $modulename ='user', $delta='1' for the login block.

... but maybe you mean something else.

.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/ |

daddydo’s picture

Something went wrong posting...Why edit is on?

daddydo’s picture

I want to have a nice little contact form in a block, that is always there no matter what node number is opened and when 'send' button is pressed, the current node stays open. Most contact forms have a error page that jumps out of the block, unless you have pointed it to it's URL page where it is originally placed (think of a separate 'contact-page'), but in this case there is not such a page. mmmm...., complicated. I found a script, that does this and cannot change it's behaviour. Now maybe there's a module for d6 but couldn't find it. The point is that the error page should stay in the block (or better the errors are not send via a new page), and the correct filled in fields should be kept. And of course no contact form without captcha and other security in its place. I know, asking too much......

daddydo’s picture

Can you remove a erradic post?

marcvangend’s picture

daddydo’s picture

Hi marc, did you read my post about the 'nice little contact form in a block'?

daddydo’s picture

d6.4 installed.
I want to have a nice little contact form in a block.

  • that is always there no matter what node number is opened
  • when 'send' button is pressed, the current node stays open
  • should verify and show errors by red borders or likewise
  • It should be very secure and anti-spam (no header injection, etc)
  • with captcha

I found something like that, but didn't match d6.
Maybe a module does exist for d6, but couldn't find it.

marcvangend’s picture

It sounds like someting you should do with AJAX, I don't know how to do it.