How do you store pictures inside of a folder in to a variable. E.g there are 27
ID: 3753149 • Letter: H
Question
How do you store pictures inside of a folder in to a variable. E.g there are 27 pictures inside of a folder and I want my program to display a few random pictures every time the page is refreshed from those 27 pictures. (BUT the pictures cannot be the same) I.e if picture A is already shown on the page, do not show picture A again unless it refreshes. Please use arrays and code in php How do you store pictures inside of a folder in to a variable. E.g there are 27 pictures inside of a folder and I want my program to display a few random pictures every time the page is refreshed from those 27 pictures. (BUT the pictures cannot be the same) I.e if picture A is already shown on the page, do not show picture A again unless it refreshes. Please use arrays and code in phpExplanation / Answer
I have two different answer
1)Use javascript inside php project and add this code
like ,
<html>
<?php
CODE HERE
?>
do some javascript or html
</html>
answer:
<html>
<head>
<script type="text/javascript">
var totalCount = 8;
function ChangeIt()
{
var num = Math.ceil( Math.random() * totalCount );
document.body.background = 'bgimages/'+num+'.jpg';
document.body.style.backgroundRepeat = "repeat";// Background repeat
}
</script>
</head>
<body>
// Page Design
</body>
<script type="text/javascript">
ChangeIt();
</script>
</html>
2 ) PURE PHP
answer:
<?php
$background = array
(
array
(
'image' => 'images/house.jpg',
'url' => 'http://google.se'
),
array
(
'image' => 'images/ocean.jpg',
'url' => 'http://disney.com'
)
);
$choice = $background[array_rand($background)];
$image = $choice['image'];
$url = $choice['url'];
?>
<body>
</body>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.