help with images in folder pleeeease

Hi guys,

wondering if someone can help with this? im rubbish with PHP but understand I need to use it, but not sure if what I want to do is possible?

ok, heres the situation.

I have an images folder.

I want to display the images in the folder with php, scale them to a smaller size (some are pretty big), display the filename and the dimensions.

i found this script which seemed perfect:
[php]<?PHP
// filetypes to display
$imagetypes = array(“image/jpeg”, “image/gif”, “image/png”,);
?>

<?PHP function getImages($dir) { global $imagetypes; // array to hold return value $retval = array(); // add trailing slash if missing if(substr($dir, -1) != "/") $dir .= "/"; // full server path to directory $fulldir = "http://www.inspirar.co.uk/demo/images/"; $d = @dir($fulldir) or die("getImages: Failed opening directory $dir for reading"); while(false !== ($entry = $d->read())) { // skip hidden files if($entry[0] == ".") continue; // check for image files if(in_array(mime_content_type("$fulldir$entry"), $imagetypes)) { $retval[] = array( "file" => "/$dir$entry", "size" => getimagesize("$fulldir$entry") ); } } $d->close(); return $retval; } ?> <?PHP // fetch image details $images = getImages("images"); // display on page foreach($images as $img) { echo "
"; echo "\"\"
\n"; echo "",basename($img['file']),"
\n"; echo "({$img['size'][0]} x {$img['size'][1]} pixels)"; echo "
\n"; } ?>[/php]

but cant get it to work, it simply says

getImages: Failed opening directory images/ for reading

finally, I can’t just use a gallery where the php generates thumbnails, as the client is going to update images but uploading new images with the same name, thumbnails don’t update so this doesnt work.

hope that makes sense?!?

any ideas???

many thanks

David

try changing this line from
[php]// full server path to directory
$fulldir = “http://www.inspirar.co.uk/demo/images/”;[/php]

to
[php]// path to directory
$fulldir = $_SERVER[‘DOCUMENT_ROOT’] . ‘/demo/images/’;[/php]

Hopefully that will get you going
:wink:

Sponsor our Newsletter | Privacy Policy | Terms of Service