div img src not displaying random image
I have code for a random image in the php section of my page
$imagesDir = 'images/eggs/';
$images = glob($imagesDir . '*.{jpg,jpeg,png,gif}', GLOB_BRACE);
$randomImage = $images[array_rand($images)];
it will display an image with this code
echo "<img src='$randomImage'>";
but when i try to do this in the body section of the page like this
<body>';
}
function template_body_above()
{
global $context, $settings, $options, $scripturl, $txt, $modSettings;
echo !empty($settings['forum_width']) ? '
<div id="wrapper" style="width: ' . $settings['forum_width'] . '">' : '', '
<div class="forest">
<div id="egg1"></div>
</div>
<div id="header"><div class="frame">
<div id="baloon1">
<img src="egg.php"/> //tried including seperate php code
<img src="<?php echo $randomImage ?>"> //php on same page
</div>
I am showing for the image source ...%3C?php...
Any help on where I'm going wrong ?
php image random
add a comment |
I have code for a random image in the php section of my page
$imagesDir = 'images/eggs/';
$images = glob($imagesDir . '*.{jpg,jpeg,png,gif}', GLOB_BRACE);
$randomImage = $images[array_rand($images)];
it will display an image with this code
echo "<img src='$randomImage'>";
but when i try to do this in the body section of the page like this
<body>';
}
function template_body_above()
{
global $context, $settings, $options, $scripturl, $txt, $modSettings;
echo !empty($settings['forum_width']) ? '
<div id="wrapper" style="width: ' . $settings['forum_width'] . '">' : '', '
<div class="forest">
<div id="egg1"></div>
</div>
<div id="header"><div class="frame">
<div id="baloon1">
<img src="egg.php"/> //tried including seperate php code
<img src="<?php echo $randomImage ?>"> //php on same page
</div>
I am showing for the image source ...%3C?php...
Any help on where I'm going wrong ?
php image random
add a comment |
I have code for a random image in the php section of my page
$imagesDir = 'images/eggs/';
$images = glob($imagesDir . '*.{jpg,jpeg,png,gif}', GLOB_BRACE);
$randomImage = $images[array_rand($images)];
it will display an image with this code
echo "<img src='$randomImage'>";
but when i try to do this in the body section of the page like this
<body>';
}
function template_body_above()
{
global $context, $settings, $options, $scripturl, $txt, $modSettings;
echo !empty($settings['forum_width']) ? '
<div id="wrapper" style="width: ' . $settings['forum_width'] . '">' : '', '
<div class="forest">
<div id="egg1"></div>
</div>
<div id="header"><div class="frame">
<div id="baloon1">
<img src="egg.php"/> //tried including seperate php code
<img src="<?php echo $randomImage ?>"> //php on same page
</div>
I am showing for the image source ...%3C?php...
Any help on where I'm going wrong ?
php image random
I have code for a random image in the php section of my page
$imagesDir = 'images/eggs/';
$images = glob($imagesDir . '*.{jpg,jpeg,png,gif}', GLOB_BRACE);
$randomImage = $images[array_rand($images)];
it will display an image with this code
echo "<img src='$randomImage'>";
but when i try to do this in the body section of the page like this
<body>';
}
function template_body_above()
{
global $context, $settings, $options, $scripturl, $txt, $modSettings;
echo !empty($settings['forum_width']) ? '
<div id="wrapper" style="width: ' . $settings['forum_width'] . '">' : '', '
<div class="forest">
<div id="egg1"></div>
</div>
<div id="header"><div class="frame">
<div id="baloon1">
<img src="egg.php"/> //tried including seperate php code
<img src="<?php echo $randomImage ?>"> //php on same page
</div>
I am showing for the image source ...%3C?php...
Any help on where I'm going wrong ?
php image random
php image random
asked Dec 31 '18 at 15:11
FlexxallFlexxall
1416
1416
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Try this way:
function template_body_above()
{
global $context, $settings, $options, $scripturl, $txt, $modSettings;
echo ( (!empty($settings['forum_width'])) ? '<div id="wrapper" style="width: ' . $settings['forum_width'] . '">' : '') .
'
<div class="forest">
<div id="egg1"></div>
</div>
<div id="header"><div class="frame">
<div id="baloon1">
<img src="' . $randomImage . '">
</div>
when i copy paste your code i get syntax error, unexpected 'template_body_above' (T_STRING)
– Flexxall
Dec 31 '18 at 15:50
@Flexxall did you add the closing bracket } ? I'm using the function now and it works on my server. I've added it in the code now
– Ass3mbler
Dec 31 '18 at 15:51
@Flexxall you can check that the function is correct and hasn't any syntax error (and test that it's working) on the following link: sandbox.onlinephpfunctions.com/code/…
– Ass3mbler
Dec 31 '18 at 15:55
the ending bracket for the function is much further down the page on my side. this is a smf forum page so theres alot of content
– Flexxall
Dec 31 '18 at 15:56
@Flexxall ok, I was guessing it and I didn't add it to the first answer for this reason. Anyway it's important there is one somewhere;)
– Ass3mbler
Dec 31 '18 at 16:00
|
show 10 more comments
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53988875%2fdiv-img-src-not-displaying-random-image%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Try this way:
function template_body_above()
{
global $context, $settings, $options, $scripturl, $txt, $modSettings;
echo ( (!empty($settings['forum_width'])) ? '<div id="wrapper" style="width: ' . $settings['forum_width'] . '">' : '') .
'
<div class="forest">
<div id="egg1"></div>
</div>
<div id="header"><div class="frame">
<div id="baloon1">
<img src="' . $randomImage . '">
</div>
when i copy paste your code i get syntax error, unexpected 'template_body_above' (T_STRING)
– Flexxall
Dec 31 '18 at 15:50
@Flexxall did you add the closing bracket } ? I'm using the function now and it works on my server. I've added it in the code now
– Ass3mbler
Dec 31 '18 at 15:51
@Flexxall you can check that the function is correct and hasn't any syntax error (and test that it's working) on the following link: sandbox.onlinephpfunctions.com/code/…
– Ass3mbler
Dec 31 '18 at 15:55
the ending bracket for the function is much further down the page on my side. this is a smf forum page so theres alot of content
– Flexxall
Dec 31 '18 at 15:56
@Flexxall ok, I was guessing it and I didn't add it to the first answer for this reason. Anyway it's important there is one somewhere;)
– Ass3mbler
Dec 31 '18 at 16:00
|
show 10 more comments
Try this way:
function template_body_above()
{
global $context, $settings, $options, $scripturl, $txt, $modSettings;
echo ( (!empty($settings['forum_width'])) ? '<div id="wrapper" style="width: ' . $settings['forum_width'] . '">' : '') .
'
<div class="forest">
<div id="egg1"></div>
</div>
<div id="header"><div class="frame">
<div id="baloon1">
<img src="' . $randomImage . '">
</div>
when i copy paste your code i get syntax error, unexpected 'template_body_above' (T_STRING)
– Flexxall
Dec 31 '18 at 15:50
@Flexxall did you add the closing bracket } ? I'm using the function now and it works on my server. I've added it in the code now
– Ass3mbler
Dec 31 '18 at 15:51
@Flexxall you can check that the function is correct and hasn't any syntax error (and test that it's working) on the following link: sandbox.onlinephpfunctions.com/code/…
– Ass3mbler
Dec 31 '18 at 15:55
the ending bracket for the function is much further down the page on my side. this is a smf forum page so theres alot of content
– Flexxall
Dec 31 '18 at 15:56
@Flexxall ok, I was guessing it and I didn't add it to the first answer for this reason. Anyway it's important there is one somewhere;)
– Ass3mbler
Dec 31 '18 at 16:00
|
show 10 more comments
Try this way:
function template_body_above()
{
global $context, $settings, $options, $scripturl, $txt, $modSettings;
echo ( (!empty($settings['forum_width'])) ? '<div id="wrapper" style="width: ' . $settings['forum_width'] . '">' : '') .
'
<div class="forest">
<div id="egg1"></div>
</div>
<div id="header"><div class="frame">
<div id="baloon1">
<img src="' . $randomImage . '">
</div>
Try this way:
function template_body_above()
{
global $context, $settings, $options, $scripturl, $txt, $modSettings;
echo ( (!empty($settings['forum_width'])) ? '<div id="wrapper" style="width: ' . $settings['forum_width'] . '">' : '') .
'
<div class="forest">
<div id="egg1"></div>
</div>
<div id="header"><div class="frame">
<div id="baloon1">
<img src="' . $randomImage . '">
</div>
edited Dec 31 '18 at 16:24
answered Dec 31 '18 at 15:28
Ass3mblerAss3mbler
3,09711617
3,09711617
when i copy paste your code i get syntax error, unexpected 'template_body_above' (T_STRING)
– Flexxall
Dec 31 '18 at 15:50
@Flexxall did you add the closing bracket } ? I'm using the function now and it works on my server. I've added it in the code now
– Ass3mbler
Dec 31 '18 at 15:51
@Flexxall you can check that the function is correct and hasn't any syntax error (and test that it's working) on the following link: sandbox.onlinephpfunctions.com/code/…
– Ass3mbler
Dec 31 '18 at 15:55
the ending bracket for the function is much further down the page on my side. this is a smf forum page so theres alot of content
– Flexxall
Dec 31 '18 at 15:56
@Flexxall ok, I was guessing it and I didn't add it to the first answer for this reason. Anyway it's important there is one somewhere;)
– Ass3mbler
Dec 31 '18 at 16:00
|
show 10 more comments
when i copy paste your code i get syntax error, unexpected 'template_body_above' (T_STRING)
– Flexxall
Dec 31 '18 at 15:50
@Flexxall did you add the closing bracket } ? I'm using the function now and it works on my server. I've added it in the code now
– Ass3mbler
Dec 31 '18 at 15:51
@Flexxall you can check that the function is correct and hasn't any syntax error (and test that it's working) on the following link: sandbox.onlinephpfunctions.com/code/…
– Ass3mbler
Dec 31 '18 at 15:55
the ending bracket for the function is much further down the page on my side. this is a smf forum page so theres alot of content
– Flexxall
Dec 31 '18 at 15:56
@Flexxall ok, I was guessing it and I didn't add it to the first answer for this reason. Anyway it's important there is one somewhere;)
– Ass3mbler
Dec 31 '18 at 16:00
when i copy paste your code i get syntax error, unexpected 'template_body_above' (T_STRING)
– Flexxall
Dec 31 '18 at 15:50
when i copy paste your code i get syntax error, unexpected 'template_body_above' (T_STRING)
– Flexxall
Dec 31 '18 at 15:50
@Flexxall did you add the closing bracket } ? I'm using the function now and it works on my server. I've added it in the code now
– Ass3mbler
Dec 31 '18 at 15:51
@Flexxall did you add the closing bracket } ? I'm using the function now and it works on my server. I've added it in the code now
– Ass3mbler
Dec 31 '18 at 15:51
@Flexxall you can check that the function is correct and hasn't any syntax error (and test that it's working) on the following link: sandbox.onlinephpfunctions.com/code/…
– Ass3mbler
Dec 31 '18 at 15:55
@Flexxall you can check that the function is correct and hasn't any syntax error (and test that it's working) on the following link: sandbox.onlinephpfunctions.com/code/…
– Ass3mbler
Dec 31 '18 at 15:55
the ending bracket for the function is much further down the page on my side. this is a smf forum page so theres alot of content
– Flexxall
Dec 31 '18 at 15:56
the ending bracket for the function is much further down the page on my side. this is a smf forum page so theres alot of content
– Flexxall
Dec 31 '18 at 15:56
@Flexxall ok, I was guessing it and I didn't add it to the first answer for this reason. Anyway it's important there is one somewhere;)
– Ass3mbler
Dec 31 '18 at 16:00
@Flexxall ok, I was guessing it and I didn't add it to the first answer for this reason. Anyway it's important there is one somewhere;)
– Ass3mbler
Dec 31 '18 at 16:00
|
show 10 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53988875%2fdiv-img-src-not-displaying-random-image%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown