Hi, i got a big problem, if i put this PHP code in an custom php block it works, but if i go to the public site it cant find the images/
<?php
$files = glob/Themes/default/images/hexcards/*.*");
for ($i=1; $i<count($files); $i++)
{
$image = $files[$i];
print $image ."<br />"; echo '<img src="'.$image .'" alt="Random image" />'."<br /><br />"; }
?>
The problem is, it puts the index.php in between, instead of using: http://domainname.de/Themes/default/images/hexcards/*.*
it uses http://domainname.de/index.php/Themes/default/images/hexcards/*.* and doesnt find the images.
Ist there a way too fix that?
Yeah, don't use relative paths.
global $settings;
$files = glob($settings['default_theme_dir'] . '/images/hexcards/*.*");
Replace the first line of your code with that and it'll use the absolute path SMF has rather than any relevant path.
I'd also suggest changing your for to a faster version:
for ($i=1, $len = count($files); $i<$len; $i++)
While a count() is not particularly expensive, not recalculating it every single time is a saving, and it is a good habit to get into.
Lainaus käyttäjältä: Arantor - lokakuu 10, 2013, 10:59:23 AP
Yeah, don't use relative paths.
... not recalculating it every single time is a saving, and it is a good habit to get into.
Listen to Arantor you should friend, excellent advice from someone well versed in SMF as well as other platforms...
<?php
global $settings;
$files = glob($settings['default_theme_dir'] . '/images/hexcards/*.*");
for ($i=1, $len = count($files); $i<$len; $i++)
{
$image = $files[$i];
echo '
<a href="'.$image .'"><img class="hexcards" src="'.$image .'" alt="Random image" /></a>';
}
?>
This doesnt work at all.
Oh, that's my bad, because I changed over from using the icky " to '
Change the " in your glob to '.
Okay works, but still not the correct source:
http://hextcg.de/home/www/web78/html/Themes/default/images/hexcards/hextcg269.jpg
This is the link now :(
Huh, I forgot how glob() worked including the full path so it wouldn't ever have worked properly for you anyway (mostly because there are much better alternatives)
<?php
global $settings;
$files = scandir($settings['default_theme_dir'] . '/images/hexcards');
foreach ($files as $thisfile)
{
if ($thisfile[0] != '.')
echo '<a href="', $settings['default_theme_url'], '/images/hexcards/', $thisfile, '"><img class="hexcards" src="', $settings['default_theme_url'], '/images/hexcards/', $thisfile, '" alt="Random image" /></a>';
}
?>
Works like a charm. Thank you.