Jump to content

Looking for a small script!


vxdom

Recommended Posts

Not sure if this is the right forum as I'm new, so I apologise in advanced if need be!

 

I'm a real n00b to PHP. I'm looking for a little image gallery script that will show all the images in one folder, take a description from a text file and create a page like this:

 

<div>{title of directory1}<img src="{thumb.jpg from directory1}" /></div>

<div>{title of directory2}<img src="{thumb.jpg from directory2}" /></div>

<div>{title of directory3}<img src="{thumb.jpg from directory3}" /></div>

 

Which would link to show the contents as:

 

<div>{text from chosen directory/description.txt}</div>

<div>{title of chosen directory}</div>

<div>{image#1}{image#2}{image#3}{image#etc}</div>

 

So..

 

Trees (image of a tree)

Benches (image of a bench)

Clouds (image of a cloud)

 

Which would link to:

 

Here are some photos I have taken of Trees.

Trees

(image of tree1) (image of tree2) (image of tree3)

 

I've been told this is a simple enough thing to do so if anyone could help me out that'd be ace,

 

Thanks a lot.

 

Dom!

Link to comment
Share on other sites

/**

* Create a Directory Map

*

* Reads the specified directory and builds an array

* representation of it.  Sub-folders contained with the

* directory will be mapped as well.

*

* @access public

* @param string path to source

* @param bool whether to limit the result to the top level only

* @return array

*/

function directory_map($source_dir, $top_level_only = FALSE)

{

if ($fp = @opendir($source_dir))

{

$filedata = array();

while (FALSE !== ($file = readdir($fp)))

{

if (@is_dir($source_dir.$file) && substr($file, 0, 1) != '.' AND $top_level_only == FALSE)

{

$temp_array = array();

 

$temp_array = directory_map($source_dir.$file."/");

 

$filedata[$file] = $temp_array;

}

elseif (substr($file, 0, 1) != ".")

{

$filedata[] = $file;

}

}

return $filedata;

}

}

 

This'll grrab everything in a directory. Then just make them into images (easy)

Link to comment
Share on other sites

Here's a simpler version, if you know the directories (or can at least put them in an array)

 

$directory = array("directory1","directory2","directory3");
foreach($directory as $dir){
$pattern = "$dir/*.(gif|jpg|jpeg|png)";//may need to modify it for the images, but it should work
$files[] = glob($pattern);
}
print_r($files);

 

The glob() function is basically like a preg_match, in which you supply a pattern, it searches the path you give it, and returns all the files (in an array basically, per directory).

Link to comment
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.