When I try to get the array content I get "Array" instead of content.
The foreach function (if it's right, I couldn't try it until now) should then post the pictures.
<?php
$slideshowdir = "./public/all/slideshow/";
if (is_dir($slideshowdir)) {
if ($dh = opendir($slideshowdir)) {
while (($slides = readdir($dh)) !== false) {
$possible_slides = $slideshowdir.array($slides);
}
}
}
foreach($possible_slides as $slide){
$picture = file($slide);
echo $picture;
}
?>
EDIT: Sorry, I wasn't 100% clear. The files I want to post are pictures.
EDIT: I solved the problem with the following code:
<?php
$possible_slides = array();
$slideshowdir = "./public/all/slideshow/";
if (is_dir($slideshowdir)) {
if ($dh = opendir($slideshowdir)) {
while (($slide = readdir($dh)) !== false) {
if (is_file ($slideshowdir.$slide)) {
$possible_slides[] = $slideshowdir.$slide;
}
}
}
}
foreach($possible_slides as $slide){
echo '<img src="'.$slide.'">';
}
?>
Please read the documentation for file()
. It returns an array of a file's contents, line by line.
What you might want to use instead is file_get_contents()
.
Also, your first loop looks fishy. I suppose you want to do this:
<?php
$possible_slides = array();
$slideshowdir = "./public/all/slideshow/";
if (is_dir($slideshowdir)) {
if ($dh = opendir($slideshowdir)) {
while (($slide = readdir($dh)) !== false) {
if (is_file ($slideshowdir.$slide)) {
$possible_slides[] = $slideshowdir.$slide;
}
}
}
}
foreach($possible_slides as $slide){
$picture = file_get_contents($slide);
echo $picture;
}
Please note that I have added a check in the while loop to make sure only files are added to $possible_slides
. This should filter out sub-directories, as well as .
and ..
.
This part seems hinky: $slideshowdir.array($slides)
Are you sure you want to concatenate an array onto a string?
Change:
$possible_slides = $slideshowdir.array($slides);
To:
$possible_slides[] = $slideshowdir.array($slides);