Hey I have a program that will allow me to find and display specific file types, but it won't work for files located in a network drive.
How do I get around this problem? here's the code:
<?php
clearstatcache();
$sourcepath = "C:/Inetpub/wwwroot/IMS/n_test";
// Replace \ by / and remove the final / if any
$root = ereg_replace( "/$", "", ereg_replace( "[\\]", "/", $sourcepath ));
// Search for required Image Files
$results = m_find_in_dir( $root,".*\.shp" );
if( false === $results ) {
echo "'{$sourcepath}' is not a valid directory\n";
} else {
print_r( $results );
}
$results = m_find_in_dir( $root,".*\.jpg" );
if( false === $results ) {
echo "'{$sourcepath}' is not a valid directory\n";
} else {
print_r( $results );
}
$results = m_find_in_dir( $root,".*\.jpeg" );
if( false === $results ) {
echo "'{$sourcepath}' is not a valid directory\n";
} else {
$new_results = str_replace("jpeg", "jpg" ,$results);//converts jpeg->jpg
print_r( $new_results );
}
$results = m_find_in_dir( $root,".*\.tif" );
if( false === $results ) {
echo "'{$sourcepath}' is not a valid directory\n";
} else {
print_r( $results );
}
$results = m_find_in_dir( $root,".*\.tiff" );
if( false === $results ) {
echo "'{$sourcepath}' is not a valid directory\n";
} else {
$new_results = str_replace("tiff", "tif" ,$results);//converts tiff->tiff
print_r( $new_results );
}
$results = m_find_in_dir( $root,".*\.bmp" );
if( false === $results ) {
echo "'{$sourcepath}' is not a valid directory\n";
} else {
print_r( $results );
}
$results = m_find_in_dir( $root,".*\.png" );
if( false === $results ) {
echo "'{$sourcepath}' is not a valid directory\n";
} else {
print_r( $results );
}
$results = m_find_in_dir( $root,".*\.gif" );
if( false === $results ) {
echo "'{$sourcepath}' is not a valid directory\n";
} else {
print_r( $results );
}
//arrange data
function m_find_in_dir( $root, $pattern, $recursive = true, $case_sensitive = false ) {
$result = array("<table border='0'>\n<tr><td>Image Type:</td></tr>\n</table>");
if( $case_sensitive ) {
if( false === m_find_in_dir__( $root, $pattern, $recursive, $result )) {
return false;
}
} else {
if( false === m_find_in_dir_i__( $root, $pattern, $recursive, $result )) {
return false;
}
}
return $result;
}
//core functions:
function m_find_in_dir__( $root, $pattern, $recursive, &$result ) {
$dh = @opendir( $root );
if( false === $dh ) {
return false;
}
while( $file = readdir( $dh )) {
if( "." == $file || ".." == $file ){
continue;
}
if( false !== @ereg( $pattern, "{$root}/{$file}" )) {
$result[] = "{$root}/{$file} <br/>";
}
if( false !== $recursive && is_dir( "{$root}/{$file}" )) {
m_find_in_dir__( "{$root}/{$file}", $pattern, $recursive, $result );
}
}
closedir( $dh );
return true;
}
function m_find_in_dir_i__( $root, $pattern, $recursive, &$result ) {
$dh = @opendir( $root );
if( false === $dh ) {
return false;
}
while( $file = readdir( $dh )) {
if( "." == $file || ".." == $file ){
continue;
}
if( false !== @eregi( $pattern, "{$root}/{$file}" )) {
$result[] = "{$root}/{$file} <br/>";
}
if( false !== $recursive && is_dir( "{$root}/{$file}" )) {
m_find_in_dir__( "{$root}/{$file}", $pattern, $recursive, $result );
}
}
closedir( $dh );
return true;
}
?>