Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
| Search | Today's Posts | Mark Forums Read
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old April 28th, 2005, 10:22 AM
Friend of Wrox
 
Join Date: Dec 2004
Location: London, London, United Kingdom.
Posts: 154
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to list files in the folder? -Sorted-

Hi,

I want to show the pictures on my website.

1st issue - multiple upload of pictures with diffrent names means I don't know a)how many pictures and b)There names.

This is my code so far:

<?php
session_start();
include ("Security.php");
?>
<html><head></head><body>

<table><tr>

<?php
$NBFile=number of GIF pictures in the current folder;

$NBPicswidth=4;
$NBPics=0;


for ($i=1; $i<=$NBFile; $i++) {

$PicName=Select picture number $i;

?><td><img border="1" src="<?php echo $Picname; ?>" align="middle"></td><?php
$NBPics=$NBPics+1;
if ( $NBPics==$NBPicswidth ) { $NBPics=0; ?><tr><?php }
}
?>

</table></body></html>

As you can see I am missing a way to check how many pictures are in the folder and how to select a picture (which I can probably do using a temporary matrix if needed)

Thks :)
  #2 (permalink)  
Old April 29th, 2005, 02:07 AM
Friend of Wrox
 
Join Date: Mar 2004
Location: Bhopal, MP, India.
Posts: 357
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to anshul
Default

Here's the code for listing files from a directory without file-extension. Either keep only images in a directory or recognize desired file-extension only, ( using regular expressions! )
<?php
if ($handle = opendir('/~path_to_directory/')) {
    while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != "..") {
            $page_name=substr($file, 0, strpos($file, "."));
            echo "$page_name<br>";
        }
    }
}
closedir($handle);
?>
Quote:
quote:quote1:
I'm afraid of regular expressions.
quote2:
http://www.mediasworks.com/literature/
  #3 (permalink)  
Old April 29th, 2005, 06:17 AM
Friend of Wrox
 
Join Date: Dec 2004
Location: London, London, United Kingdom.
Posts: 154
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Final code working :)
Thks for your help Anshul.

<?php
session_start();
include ("Security.php");

$NBFile=0;

if ($handle = opendir('../Pictures')) {
    while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != "..") {
        if (substr($file, strlen($file)-3, 3)=="jpg" ) {
            $FileArray[] = $file;
            $NBFile=$NBFile+1;
        }

        }
    }
}
closedir($handle);

?>
<html><head></head><body>

<Center><table><tr>
<?php
$NBPicswidth=4;
$NBPics=0;
$NBFile=$NBFile-1;

for ($i=0; $i<=$NBFile; $i++) {
$Pic_Name1=$FileArray[$i];
?><td>
<img border="1" src="<?php echo $Pic_Name1; ?>" align="middle" width="100" height="75">
<p align="center" style="margin-top: -2; margin-bottom: 5"><?php echo $Pic_Name1; ?></td><?php
$NBPics=$NBPics+1;

if ( $NBPics==$NBPicswidth ) { $NBPics=0; ?><tr><?php }
}
?>

</table></body></html>


Similar Threads
Thread Thread Starter Forum Replies Last Post
List name of item from folder 'My Picture' mona_upm84 Excel VBA 2 September 4th, 2008 05:54 PM
Files need to move different folder surendran PHP How-To 2 June 20th, 2006 10:27 PM
FILES in FOLDER luma SQL Server DTS 0 June 9th, 2005 01:53 AM
Outlook Express folder list in vba louisantony Access VBA 0 December 30th, 2003 04:16 AM
Search in a sorted list yajleejnus Classic ASP Basics 0 June 11th, 2003 04:00 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.