1

i create this function for search resume file from directory, if resume is available then function return full path, problem is function return nothing if i use "return", if i use "echo" then it will print right path

 function search_resume($resume,$dir="uploads/resumes")
{
    $root = scandir($dir);
    foreach($root as $value)
    {
        /* echo $value."<br/>"; */
        if($value === '.' || $value === '..') {continue;} 
        if(is_file("$dir/$value"))
        {
            if($value==$resume)
            {
                $path="$dir/$value";
                return $path;
            }
        }
        else
        {
            search_resume($resume,"$dir/$value");
        }
    }
}
2
  • 1
    What's the point of this function? if you know what dir to look under, and you know the file-name, why yould you bneed this recursive function to scan directories N levels deep? Commented Jan 27, 2014 at 10:38
  • You're ignoring search_resume() return value. Commented Jan 27, 2014 at 10:40

1 Answer 1

1

A very typical, basic problem with recursive functions: you need to return recursive calls as well, they're not going to return themselves.

    ...
    else {
        $path = search_resume($resume,"$dir/$value");
        if ($path) {
            return $path;
        }
    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.