Jump to content

Recommended Posts

Hey Peoples :P,

I Made This For My Image Gallery

<?php
$thumbs = scandir('image');

foreach($thumbs as $thumb)
{
    if(substr($thumb, 0, 1) !== '.')
        echo '<img src="image/', $thumb, '"/ width="200" height="200">';
	echo '<a href="image/', $thumb, '"/>View Normal Size</a>';
}

?>

 

And It's Displaying It How It Should Execpt I Get Two Extra Links At The Front That Link To The Image Dir And One Links To The Main Root.

 

What Can You Guys Do? :P

Link to comment
https://forums.phpfreaks.com/topic/111551-solved-scan-dir/
Share on other sites

Don't Worry I Fixed Them Links But Now,

<?php
$thumbs = scandir('image');

foreach($thumbs as $thumb)
{
     if ($thumb[0]=='.') continue;
     if ($thumb[0]=='index.html') continue;
        echo '<img src="image/', $thumb, '"/ width="200" height="200">';
	echo '<a href="image/', $thumb, '"/>View Normal Size</a>';
}

?>

 

I Can't Make It Skip The Index.html file

Link to comment
https://forums.phpfreaks.com/topic/111551-solved-scan-dir/#findComment-572569
Share on other sites

<?php
$file_types = array('gif', 'jpg');

foreach(scandir('image') as $thumb)
{
    if (is_file($thumb) && in_array(end(explode('.', $thumb)), $file_types)) {
        echo '<img src="image/', $thumb, '"/ width="200" height="200">';
        echo '<a href="image/', $thumb, '"/>View Normal Size</a>';
    }
}

?>

Link to comment
https://forums.phpfreaks.com/topic/111551-solved-scan-dir/#findComment-572606
Share on other sites

There was some errors in the echo code.

 

I fixed that and made it more modular. Try this:

 

<?php

$file_types = array('gif','jpg');
$directory = 'image';

foreach(scandir($directory) as $thumb)
{
    if (is_file("$directory/$thumb") && in_array(end(explode('.', $thumb)), $file_types))
    {
        echo "<img src=\"$directory/$thumb\" width=\"200\" height=\"200\">";
        echo "<a href=\"$directory/$thumb\">View Normal Size</a>";
    }
}

?>

Link to comment
https://forums.phpfreaks.com/topic/111551-solved-scan-dir/#findComment-572620
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.