Reputation: 100
I am importing some files to a folder using everything is ok and all the files get inserted normally, but the problem begins when I try to show thumbnails of these files on my browser. In this case just some of the files can be shown perfectly and others are shown az empty rectangular! While all the files are located in the same folder! I investigated more and realized that the images that their original source(on computer) was close to the folder path are being shown perfectly and others not.
For instance my folder locates in: c://xampp/htdocs/test/folder I have put all the picturs in folder, but just the images that originally where available at c://xampp/htdocs/test are being shown and not others.
Please help me
the code:
$images=array();
$dir_handler = opendir('test/folder') or die("Unable to open $path");
$i=0;
while($file = readdir($dir_handler))
{
if(is_dir($file))
continue;
else if($file != '.' && $file != '..' && $file != 'index.php')
{
$images[$i]=$file;
$i++;
}
}
sort($images);
for($i=0; $i<sizeof($images); $i++)
{
echo "<a href=".chr(34).$path.$images[$i].chr(34)."><img style='border:1px solid #666666; width:100px;height:100px; margin: 10px;' src='".$images[$i]."'/></a>";
} closedir($dir);
Upvotes: 0
Views: 60
Reputation: 1177
It may be more helpful to use SPL's Directory iterator in this case.
In this code example, I'm assuming your path was to 'test/folder' - which contained images and an index.php file.
$path = 'test/folder';
foreach (new DirectoryIterator($path) as $fileInfo) {
if ($fileInfo->isFile() && $fileInfo->getFilename() != 'index.php') {
$image = "{$path}/{$fileInfo->getFilename()}";
echo "<a href='{$image}'><img src='{$image}'></a>"; // style as appropriate
}
}
This creates a new DirectoryIterator on your path. Then, if the result is indeed a file, and not named index.php, the variable $image is populated with the path and the filename. The echo statement has a shorter version of your example code to output the a/img tag combination.
Upvotes: 0
Reputation: 24276
I think your images src path should be src='folder/".$images[$i]."'
Upvotes: 1