I have a php script that runs glob on a directory, and it returns all the images it finds in the directory, with an ad from google before all the images. I would like it if I could use glob to load 10 of the images, then insert the javascript from googles ad services, and continue loading the images. So an ad every 10 images. Every attempt by me so far has failed spectacularly, and any help would be greatly appreciated!
Below is my PHP code
<?php
$manualwidth = $_GET['manwidth'];
$manualdir = $_GET['mandir'];
$manualmodel = $_GET['manurl'];
$manualurl = $manualdir . '/' . $manualmodel . '/';
$files = glob($manualurl .'{*.jpg,*.gif}', GLOB_BRACE);
for ($i=0; $i<count($files); $i++)
{
$num = $files[$i];
echo '<img src="'.$num.'" width="'.$manualwidth.'"><br>'." ";
}
?>
Echo the js every 10th iteration
<?php
$count = count($files);
for ($i=0; $i<$count; $i++)
{
if($i % 10 === 0) {
echo "google ads here";
}
$num = $files[$i];
echo '<img src="'.$num.'" width="'.$manualwidth.'"><br>'." ";
}
?>
How about putting the ad code into an html file in the directory:
ad.html
<script type="text/javascript>
//Code to run
</script>
//other ad stuff here
And then just include that file after every 10 images:
index.php
<?php
for($i = 1; $i <= count($files); $i++)
{
//Echo image code here
if($i%10 == 0)
include("ad.html");
}