Web Hosting Talk







View Full Version : batch image bb code generator


roby2k
03-05-2006, 12:10 PM
any one got a script that will scan a directory and then generate code for all the files

i.e
i upload loads of pictures
then run the script and it gives me a box to copy and paste so all the IMG tags are in

Neoboffin
03-05-2006, 01:29 PM
Try this:

<?php
$URL = "http://mydomain.com/path/to/images/";
if($DIR = opendir('.'))
{
echo '<textarea name="textarea" cols="70" rows="8">';
while(false !== ($File = readdir($DIR)))
{
if(fnmatch('*.gif', $File) || fnmatch('*.jpg', $File) || fnmatch('*.png', $File))
{
echo "" . $URL . $File . "\n";
}
}
echo '</textarea>';
closedir($DIR);
}
?>

Specify a URL to the image directory with an end slash (like above) then put the script in the directory where the images are and execute it. It will check for .gif, .jpg and .png.

Burhan
03-06-2006, 01:41 AM
#automatically calculate the URL
$url = strtolower(substr($_SERVER['SERVER_PROTOCOL'],0,strpos($_SERVER['SERVER_PROTOCOL'],'/'))).'://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']).'/';

$images = glob("{*.png,*.jpg,*.jpeg,*.gif}",GLOB_BRACE);
foreach ($images as $filename)
{
echo ''.$url.$filename.'<br />';
}