PDA

View Full Version : Help please displaying an image after reading a file


Sicilian
10-20-2014, 08:15 AM
I've been trying to add some code in a Forum block to display a status image that shows on one of our download sites www.openvix.co.uk

I've tried adding the code below to a sidebar block and advertising block, but all that vbulletin outputs is: -

'; ?>

Code I'm using is below: -

<?php

$domain = 'http://openvix.co.uk/';
$StatusFile = "./feeds/status";

$states = array('stable', 'un-stable', 'updating');

if(($currentState = @file_get_contents($domain.$StatusFile)) !== false)
{
$currentState = intval(trim($currentState));
}
else
{
$currentState = 2;
}

print '<img src="'.$domain.$states[$currentState].'.png" class="statusimage" alt="OpenViX status: '.$states[$currentState].'" />';

?>

Any ideas anyone please?

Thanks in advance.

kh99
10-20-2014, 09:59 AM
You want to create a "Custom HTML/PHP" block and make sure you select the "PHP" radio button in the Content Type section. Then you need to "return" the output instead of printing it.

Try using this code:

$domain = 'http://openvix.co.uk/';
$StatusFile = "./feeds/status";

$states = array('stable', 'un-stable', 'updating');

if(($currentState = @file_get_contents($domain.$StatusFile)) !== false)
{
$currentState = intval(trim($currentState));
}
else
{
$currentState = 2;
}

return '<img src="'.$domain.$states[$currentState].'.png" class="statusimage" alt="OpenViX status: '.$states[$currentState].'" />';


Of course the "Cache Time" setting will control how often it updates. If you want every page request to check you could set it to 0, but if you have a busy forum it could take a lot of server time, so it would be better to set it to at least 1, if it's acceptable to have it update only once per minute.

Sicilian
10-20-2014, 10:05 AM
Thank you, just tested, no joy :(

See attached.

Sicilian
10-20-2014, 10:07 AM
Sorry, my mistake, had HTML checked.

Massive thank you for your help :)