Jump to content

PHP file Handling problems, help desired


bubazoo

Recommended Posts

Hey guys,

ok, well, so far I have this bit of code:

[code]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<title>Directory Contents</title>
</head>
<body>

// Set the directory name and open it.
$search_dir = '.';
$dp = opendir ($search_dir);


// List the files.
while ($item = readdir ($dp) ) {
if ( (is_file ($item)) AND (substr ($item, 0, 1) != '.') ) {


// Print the information.
print $item;

} // Close the IF.

} // Close the WHILE.

closedir ($dp); // Close the directory.

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

that I made up using the PHP Manual mostly,

but instead of printing out the files to the screen, how do I convert the filenames into an array?

and how do I limit the listing to only jpg, gif, and png file extensions?

I realize that PHP 5 uses the "scandir()" function that automatically does this, but my host has me on PHP 4.4.4 so I am forced to figure this out the manual way

thanks guys,


Basically what I am trying to do, is a Photo gallery like [url=http://www.cssplay.co.uk/menu/slide_show.html]this one[/url]

except, instead of using XHTML to insert the image filenames manually, get a list of image files inside the current directory and display them to that CSS style photo gallery..  I'll probably also remove the "mouseover" thing so the gallery always stays on the page, but thats basically what I am trying to do with this.

then I'll name that file "index.php" and put it inside my "/photos/home_pics" directory with a bunch of images in it.  thanks guys.

almost forgot.

I know to create arrays you do like

$variable = array (1 => 'something', 'something2');

etc but what I don't understand  is how to put $item  into an array thats within a while loop like that

thanks
Link to comment
https://forums.phpfreaks.com/topic/30888-php-file-handling-problems-help-desired/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.