Click to See Complete Forum and Search --> : [RESOLVED] Search a file
sveegaard
Jun 14th, 2006, 08:56 AM
Hi,
I want to search a file's directory - so, if I search the file 0466-01-03.sldprt, PHP returns the path where the file is. All files are unique and on the server's filesystem (intranet).
Is that possible?
john tindell
Jun 14th, 2006, 10:44 AM
Try something like this, you have to read all the files in the directory and match them.
<?php
if ($handle = opendir('.')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
if($file == "0466-01-03.sldprt"){ //match file
//do stuff with the file here
}
}
}
closedir($handle);
}
?>
The only other method i can think of would be to use exec() (http://uk2.php.net/exec) and execute "ls" or "dir" with the filename. and parse the results.
sveegaard
Jun 14th, 2006, 03:03 PM
Does that also work if the files are saved in other directories, eg. ../01/03? Engineers aren't predictable when it's about saving the files :P
john tindell
Jun 14th, 2006, 03:38 PM
jsut change the parameter passed to opendir() (http://uk2.php.net/opendir). You can check to see if the item return is a file or a directory using is_file() (http://uk2.php.net/is_file) or is_dir() (http://uk2.php.net/is_dir)
penagate
Jun 15th, 2006, 04:55 AM
You could make a recursive search function, if any result is a directory you call the function again with that base path.
sveegaard
Jun 15th, 2006, 09:21 AM
It won't work...it just prints a blank screen
sveegaard
Jun 15th, 2006, 09:26 AM
Oh, it's case sensitive :D
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.