hi,
I am a new member of daniwab. Pl, help me. Just i want php codings to search images in a folder(including subfolders) in my drive. Search is just like windows search program.
But i want to search images without using database. Just i type any code word (for eg:- fruits) in the search box, then it will displays all the fruits in my folder(including subfolders)

Hi,
Your problem is solved or you still facing problem ??

Hi,
Your problem is solved or you still facing problem ??

Hi Aamit,
Thanks in advance for trying to solve my problem. I didn't sove this problem. Pl help me if you know the way.

Yes It's possible to search files on your drive like c: or d: or e:

$search="DIR /s e:\*.gif>>out.txt";
system ($search);

Here you use dir windows command to search *.gif images on
e: (e drive) and store result in out.txt file

If you check out.txt file you will see all result like search function.
DIR /s e:\*.gif>>out.txt
In this >>out.txt to write result in out.txt file if you don't want remove this....i am giving this to check result..

then /s for searching file including sub folders in your path...
here path is e:

you have write code for what you search and create string
like DIR /s e:\*.gif this

when you found record move image to your destination folder
Hope it helps you...

Hi Aamit,
I am trying your code but it displays some warning like 'system() function facing a security problem'. So i cant get the result.
Next, i am working in a networked system. Just i want to search all the images in the H: drive. What i am exactly trying to say is, i want a search program exactly as 'istockphoto.com' of my own. Could you tell me this is possible for writing code in php.

first check on command prompt :- DIR /s h:\*.gif>>out.txt
if not working that means you don't have authority to use cmd ...
so first make user i.e you to User Account doesn't have admin privileges check for that....on google how to get admin privileges

In istockphoto.com i think they are using ajax +database whenever you type some text it gives you the category for that ..
so you have to create database & manage it using
php+ mysql+ ajax
search for ajax you got the lots of image example for it...

<?php

function isImage($fileName)
{
	$ext = substr(strrchr($fileName, '.'), 1);	
	
	if($ext <> "")
	{
		$ext = strtolower($ext);
		switch($ext)
		{
			case 'gif': return true;
			case 'jpeg': return true;
			case 'png': return true;
			case 'psd': return true;
			case 'bmp': return true;
			case 'tiff': return true;
			case 'jp2': return true;
			case 'iff': return true;
			case 'ico': return true;
			default: return false;
		}
	}
	else
		 return false;
	
}

function ListMyFiles($dir,$MySearchFile) 
{
	    if($dh = opendir($dir)) 
	   {
		$files = Array();
		$inner_files = Array();

		while($file = readdir($dh)) 
		{
			    if($file != "." && $file != ".." && $file[0] != '.') 
			    {
					if(is_dir($dir . "/" . $file)) 
					{
						
					    $inner_files = ListMyFiles($dir . "/" . $file,$MySearchFile);
					    if(is_array($inner_files)) 
						$files = array_merge($files, $inner_files); 
					    
					} 
					else 
					{
						
						if($MySearchFile == "")
						{
							if(isImage($file))
							{
								array_push($files, $dir . "/" . $file);
							}
						}
						else if ( strstr( $file,$MySearchFile ) )
						{
							if(isImage($file))
							{
								array_push($files, $dir . "/" . $file);
							}
						}
					}
			    }
		}

		closedir($dh);
		return $files;
	    }
}


//NOTE : if u don't want to search by keywords plesae keep this field blank
$MySearchFile = "test";

foreach(ListMyFiles('includes/',$MySearchFile) as $file_name)
{
    
    echo "<br>".$file_name;
    
}  

?>
<?php

function isImage($fileName)
{
	$ext = substr(strrchr($fileName, '.'), 1);	
	
	if($ext <> "")
	{
		$ext = strtolower($ext);
		switch($ext)
		{
			case 'gif': return true;
			case 'jpeg': return true;
			case 'png': return true;
			case 'psd': return true;
			case 'bmp': return true;
			case 'tiff': return true;
			case 'jp2': return true;
			case 'iff': return true;
			case 'ico': return true;
			default: return false;
		}
	}
	else
		 return false;
	
}

function ListMyFiles($dir,$MySearchFile) 
{
	    if($dh = opendir($dir)) 
	   {
		$files = Array();
		$inner_files = Array();

		while($file = readdir($dh)) 
		{
			    if($file != "." && $file != ".." && $file[0] != '.') 
			    {
					if(is_dir($dir . "/" . $file)) 
					{
						
					    $inner_files = ListMyFiles($dir . "/" . $file,$MySearchFile);
					    if(is_array($inner_files)) 
						$files = array_merge($files, $inner_files); 
					    
					} 
					else 
					{
						
						if($MySearchFile == "")
						{
							if(isImage($file))
							{
								array_push($files, $dir . "/" . $file);
							}
						}
						else if ( strstr( $file,$MySearchFile ) )
						{
							if(isImage($file))
							{
								array_push($files, $dir . "/" . $file);
							}
						}
					}
			    }
		}

		closedir($dh);
		return $files;
	    }
}


//NOTE : if u don't want to search by keywords plesae keep this field blank
$MySearchFile = "test";

foreach(ListMyFiles('includes/',$MySearchFile) as $file_name)
{
    
    echo "<br>".$file_name;
    
}  

?>

Hi,
I am still facing the problem. Error in opendir(). failed to open dir
opendir command does not support anway.
Pl anybody help me?

Ya! Its working but it dispalys only the filename like 001.jpg, 002.gif, 003.png etc.

But i want the image to display not the filename. Just like image search in google. could anybody help me???????????

try this code....

$cnt = 1;
$number_of_image_per_row = 6;
$width = 50; //Define image width
$height = 50 //Define image height

foreach(ListMyFiles('includes/',$MySearchFile) as $file_name)
{
      if($cnt % $number_of_image_per_row == 0)
	      echo "<br>";
      
	echo "<image src='".$file_name."'  $width $height >";
      
      $cnt++;
    
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.