/    Sign up×
Community /Pin to ProfileBookmark

display images in a folder

Hi I am trying to display all the images in a certain folder.

I dont want to display the directory itself of the parent directory.

I would like to show the actual photos instead of the links also.

Here is the code:

[code=php]<?php
session_start();
?><!doctype html public “-//W3C//DTD HTML 4.0 //EN”>
<html>
<head>
<title>Easy display</title>
</head>
<body>
<?php

$dirname = “./imagesFolder/user${_SESSION[‘user’]}/”;
$images = scandir($dirname);
foreach($images as $curimg){
echo “<a href=’./imagesFolder/user${_SESSION[‘user’]}/$curimg’>$curimg</a><br>n”;
};

?>
</body>
</html>[/code]

Any suggestions?

Thanks in advance!

to post a comment
PHP

16 Comments(s)

Copy linkTweet thisAlerts:
@Suhas_DhokeJan 10.2008 — Use the <IMG> tag instead of Anchor Tag (<A>) for displaying the image, instead of a link.
Copy linkTweet thisAlerts:
@smickusJan 10.2008 — and you can have an if inside the foreach statement...
[code=php]
$ignore = Array(".", "..", "otherfiletoignore");
foreach($images as $curimg){
if(!in_array($curimg, $ignore)) {
echo "<img src='./imagesFolder/user${_SESSION['user']}/$curimg' /><br>n";
};
}
[/code]
Copy linkTweet thisAlerts:
@graphical_forceauthorJan 10.2008 — Thanks guys that did the trick!
Copy linkTweet thisAlerts:
@graphical_forceauthorJan 10.2008 — I now would like to display the images in a thumbnail. I'm not sure how to proceed with that. I have read something about getimagesize() but I am not sure if this is what I would use or how I would use it in this situation.

Here is the code:
[code=php]<?php
session_start();
?><!doctype html public "-//W3C//DTD HTML 4.0 //EN">
<html>
<head>
<title>Easy display</title>
</head>
<body>
<a href="../main.page.php">back to main page</a><br/><br/>
<?php

$dirname = "./imagesFolder/user${_SESSION['user']}/";
$images = scandir($dirname);
$ignore = Array(".", "..");
foreach($images as $curimg){
if(!in_array($curimg, $ignore)) {
echo "<img src='./imagesFolder/user${_SESSION['user']}/$curimg' /><br>n";
};
}
?>
</body>
</html>[/code]


Any suggestions on how to create thumbnails out of any image in a particular folder?
Copy linkTweet thisAlerts:
@smickusJan 11.2008 — Do you have the GD Images library installed? Or do you just want to use a new height/width to make the image look smaller?
Copy linkTweet thisAlerts:
@graphical_forceauthorJan 11.2008 — I am not sure if I have the GD Library installed but I believe I do. I have done a little research and came up with some code that will change the images in a folder to thumbnails and it requires the GD Library and it appears to work. But I am not sure if this is the best way for me. The problem that I have is that some images will be 1536 x 2048 or 2048 x 1536. I need them to resize no matter which dimension is bigger. I then want to add a radio button or some control that will allow the user to choose a image.

I am open to any other suggestions.

Thanks.
Copy linkTweet thisAlerts:
@hex1a4Jan 11.2008 — Hi,

[url="http://sye.dk/sfpg/"]This script[/url] might be what you're looking for. It looks for images in a directory, creates thumbnails (if it hasn't already) and displays them, making the thumbnails clickable to see the full image. Plus it has features, is easy to configure, and of course you can modify it to suit your needs.
Copy linkTweet thisAlerts:
@graphical_forceauthorJan 14.2008 — Thanks for all the ideas but I found a solution to my problem. ?
Copy linkTweet thisAlerts:
@tryingIThardOct 04.2011 — HI Graphical Force,

It would be nice to let us know what solution have you found as others including myself are interested.

thanks...
Copy linkTweet thisAlerts:
@Henry07May 07.2013 — this is a php code

<?

$files = glob("images/*.*");

for ($i=0; $i<count($files); $i++)

{

$num = $files[$i];

echo '<img src="'.$num.'" alt="random image" />'."<br><br>";

}

?>
Copy linkTweet thisAlerts:
@ThomasJMay 24.2013 — Hi,

I came across this post and it works excellent, but the images are all loaded in a vertical line.

1. How do I change this to be Horizontal until page is full and then move to second line.


2. How do I add in the image name (file name) for each image.

Using your code below:

<?php

$dirname = "pictures/test";

$images = scandir($dirname);

$ignore = Array(".", "..", "otherfiletoignore");

foreach($images as $curimg){

if(!in_array($curimg, $ignore)) {

echo "<img src='pictures/test/$curimg' /><br>n";

};

}


?>

Thanks,
Copy linkTweet thisAlerts:
@Dragonfire2008May 24.2013 — echo "<img style="float:right;" src='pictures/test/$curimg' /><br>n";

that should do the trick....
Copy linkTweet thisAlerts:
@ThomasJMay 27.2013 — Hi,

Thanks no the images are floating to the right, but not in line.

See updated scripting and attached image:

<?php

$dirname = "pictures/test";

$images = scandir($dirname);

$ignore = Array(".", "..", "otherfiletoignore");

foreach($images as $curimg){

if(!in_array($curimg, $ignore)) {

echo "<img style='vertical-align: middle; float: right'; title='$curimg'; src='pictures/test/$curimg'; /><br>n";

};

}


?>
Copy linkTweet thisAlerts:
@ThomasJMay 27.2013 — If previous post comes through I was being a plank.... I just removed the <Br/> tag.

Thank for the help,
Copy linkTweet thisAlerts:
@Henry07Jul 30.2013 — this is a php code

<?

$files = glob("images/*.*");

for ($i=0; $i<count($files); $i++)

{

$num = $files[$i];

echo '<img src="'.$num.'" alt="random image" />'."<br><br>";

}

?>[/QUOTE]




Duplichecker - Plagiarism software
Copy linkTweet thisAlerts:
@rootJul 30.2013 — All you need to get thumb nails is to use the getimagesize() function in conjunction with list() to obtain the height and width of the image then use a calculation to ensure that the resizing of height and width is not going to result in an image that is out of proportion.

I used something like this for my images

[code=php]$ext = array("jpg","png","gif","bmp");
foreach($ext as $typ){
$dir = glob("*.{$typ}");
$img = array_combine( $dir , $img);
}

$ratio = 0.33; // approx 1/3rd

foreach($img as $thumb){
list($width, $height, $type, $attr) = getimagesize( $thumb );
$height = $height * $ratio;
$width = $width * $ratio;
echo "<img height='{$height}' width='{$width}' title='' src='{$thumb}'; /><br>rn";

}[/code]


its been a long time since I looked at the script but thats the basics of what I did.
×

Success!

Help @graphical_force spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...