|
-
Jun 14th, 2006, 08:56 AM
#1
Thread Starter
Addicted Member
[RESOLVED] Search a file
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?
-
Jun 14th, 2006, 10:44 AM
#2
<?="Moderator"?>
Re: Search a file
Try something like this, you have to read all the files in the directory and match them.
PHP Code:
<?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() and execute "ls" or "dir" with the filename. and parse the results.
-
Jun 14th, 2006, 03:03 PM
#3
Thread Starter
Addicted Member
Re: Search a file
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
-
Jun 14th, 2006, 03:38 PM
#4
<?="Moderator"?>
Re: Search a file
jsut change the parameter passed to opendir(). You can check to see if the item return is a file or a directory using is_file() or is_dir()
-
Jun 15th, 2006, 04:55 AM
#5
Re: Search a file
You could make a recursive search function, if any result is a directory you call the function again with that base path.
-
Jun 15th, 2006, 09:21 AM
#6
Thread Starter
Addicted Member
Re: Search a file
It won't work...it just prints a blank screen
-
Jun 15th, 2006, 09:26 AM
#7
Thread Starter
Addicted Member
Re: Search a file
Oh, it's case sensitive
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|