| | |
could i search images in a folder using php in offline
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Dec 2008
Posts: 19
Reputation:
Solved Threads: 1
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)
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)
•
•
Join Date: Apr 2008
Posts: 293
Reputation:
Solved Threads: 11
Yes It's possible to search files on your drive like c: or d: or e:
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...
PHP Syntax (Toggle Plain Text)
$search="DIR /s e:\*.gif>>out.txt"; system ($search);
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...
Last edited by Aamit; Dec 22nd, 2008 at 3:44 am.
•
•
Join Date: Dec 2008
Posts: 19
Reputation:
Solved Threads: 1
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.
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.
•
•
Join Date: Apr 2008
Posts: 293
Reputation:
Solved Threads: 11
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...
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...
•
•
Join Date: Dec 2008
Posts: 20
Reputation:
Solved Threads: 1
<?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;
}
?> -- Manish Singh
manish.s@neuralit.com
manish.s@neuralit.com
•
•
Join Date: Dec 2008
Posts: 19
Reputation:
Solved Threads: 1
•
•
•
•
<?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???????????
Last edited by ashafaaiz; Dec 24th, 2008 at 5:30 am.
•
•
Join Date: Dec 2008
Posts: 20
Reputation:
Solved Threads: 1
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++;
} Last edited by manish.s; Dec 24th, 2008 at 8:35 am.
-- Manish Singh
manish.s@neuralit.com
manish.s@neuralit.com
![]() |
Similar Threads
- Help me with my myspace clone (PHP)
- I NEED HELP PLEASE:Warning: mysql_num_rows(): (PHP)
- I NEED HELP PLEASE:Warning: mysql_num_rows(): (MySQL)
- Warning: mysql_num_rows(): (PHP)
Other Threads in the PHP Forum
- Previous Thread: adding subcategory
- Next Thread: PHP and Flash Form help
| Thread Tools | Search this Thread |
# 5.2.10 ajax apache api array beginner binary broken cakephp checkbox class clean clients cms code cron curl database date display dissertation dynamic echo echo$_get[x]changingitintovariable... email error file files folder form forms function functions google href htaccess html image images include insert integration ip java javascript joomla ldap legislation limit link local login loop mail memberships menu mlm multiple multipletables mysql mysqlquery oop open paypal pdf persist php problem query radio random recursion regex remote rss script search server sessions sms soap sockets source space spam sql syntax system table tutorial update upload url validator variable video web xml youtube





