chokri Posted September 14, 2006 Share Posted September 14, 2006 this is the first time i'm using php for website development. i'm having issues with a fileSearch function i created to return a file's location. the code is as follows:[code] function fileSearch($tempFile,$curdirLoc) { $fileFound = false; $compfileLoc = null; $curDir = scandir($curdirLoc); foreach($curDir as $curEntry) { if($curEntry != "." && $curEntry != "..") { $myLoc = $curdirLoc."\\".$curEntry; if(is_dir($myLoc)) { fileSearch($tempFile,$myLoc); } else { if(strcmp($curEntry,$tempFile) == 0) { $compfileLoc = $myLoc; $fileFound = true; } } } } if($fileFound) {return $compfileLoc;} }[/code]i know the code works and finds the file. the problem is when returning $compfileLoc.if $compfileLoc = "c:\Inetpub\wwwroot\website\sitemap.php" it worksif $compfileLoc = "c:\Inetpub\wwwroot\website\Content\Contact_Us\Contact_Information.php" it doesn't work.are there any limits to what can be returned? i can't imagine the "\" causing problems since it works for some files. i'd truly appreciate any help that can be provided! Link to comment https://forums.phpfreaks.com/topic/20737-filesearch-return-not-working/ Share on other sites More sharing options...
Orio Posted September 14, 2006 Share Posted September 14, 2006 Try chaning the code this way:[code]<?php function fileSearch($tempFile,$curdirLoc) { $fileFound = false; $compfileLoc = null; $curDir = scandir($curdirLoc); foreach($curDir as $curEntry) { if($curEntry != "." && $curEntry != "..") { $myLoc = $curdirLoc."\\".$curEntry; if(is_dir($myLoc)) { $compfileLoc=fileSearch($tempFile,$myLoc); if(compfileLoc!==FALSE){return $compfileLoc;} } else { if(strcmp($curEntry,$tempFile) == 0) { $compfileLoc = $myLoc; $fileFound = true; } } } } if($fileFound) {return $compfileLoc;} else{return FALSE;} }?>[/code]Orio. Link to comment https://forums.phpfreaks.com/topic/20737-filesearch-return-not-working/#findComment-91791 Share on other sites More sharing options...
chokri Posted September 14, 2006 Author Share Posted September 14, 2006 YOU ROCK! that worked.THANK YOU THANK YOU THANK YOU THANK YOU THANK YOUi ate many, many smarties trying to figure out what was wrong. Link to comment https://forums.phpfreaks.com/topic/20737-filesearch-return-not-working/#findComment-91803 Share on other sites More sharing options...
chokri Posted September 14, 2006 Author Share Posted September 14, 2006 i spoke too soon.previously:if $compfileLoc = "c:\Inetpub\wwwroot\website\sitemap.php" [b]it works[/b]if $compfileLoc = "c:\Inetpub\wwwroot\website\Content\Contact_Us\Contact_Information.php" [b]it doesn't work[/b]after doing as you suggested orio, now it's:if $compfileLoc = "c:\Inetpub\wwwroot\website\sitemap.php" [b]it doesn't work[/b]if $compfileLoc = "c:\Inetpub\wwwroot\website\Content\Contact_Us\Contact_Information.php" [b]it works[/b] Link to comment https://forums.phpfreaks.com/topic/20737-filesearch-return-not-working/#findComment-91812 Share on other sites More sharing options...
Orio Posted September 14, 2006 Share Posted September 14, 2006 I [i]think[/i] it should work fine now :)[code]<?php function fileSearch($tempFile,$curdirLoc) { $fileFound = false; $compfileLoc = null; $curDir = scandir($curdirLoc); foreach($curDir as $curEntry) { if($curEntry != "." && $curEntry != "..") { $myLoc = $curdirLoc."\\".$curEntry; if(is_dir($myLoc)) { $compfileLoc=fileSearch($tempFile,$myLoc); if(compfileLoc!==FALSE){return $compfileLoc;} } else { if(strcmp($curEntry,$tempFile) == 0) { $compfileLoc = $myLoc; return $compfileLoc; } } } } if($fileFound) {return $compfileLoc;} else{return FALSE;} }?>[/code]Orio. Link to comment https://forums.phpfreaks.com/topic/20737-filesearch-return-not-working/#findComment-91850 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.