views:

50

answers:

2

My project files are located on remote server in the folder. I access a file in this folder in this way:

http://www.example.com/searchtest.html

This opens a page with Input Box where user types keywords to search. The search script is a .php file located in the root itself. The script has to search for .html files with the name similar to the keywords entered. These .html files are also located in the same root folder where all .php files reside.

My application is running well when I work on local machine and is able to search well, but when I hosted it on my site, it gives error:

Warning: file_get_contents(//.rnd) [function.file-get-contents]: failed to open stream: Permission denied in /home/myServer/public_html/example/search1.php on line 40 .rnd

It is giving error on a line where I am trying to access files in my directory. Below is my code snippet. And yes, I am the administrator and I have all privileges on my site.

$matchingFiles = array();
$dirName = "\\";
$dh = opendir($dirName);
while(  ($file = readdir($dh))  !== false)
{
        $fullPath = $dirName . "/" . $file;
        if(is_dir($fullPath)) continue; // Skip directories

        similar_text($lcSearch,strtolower($file),$percentSimilar);
        if($percentSimilar >= $percentMatch)
        {
                $matchingFiles[] = $fullPath;
        }
}

It gives error probably in the "opendir" function.

I also want to know whether the $dirName holds correct path or not. It must hold the same path from where the correct script is run.

A: 

The warning you are getting is for the file_get_contents function, but I don't see that in your code snippet. What is line 40 of search1.php?

RMcLeod
@RMcLeod: i am sorry. That line looks like this:foreach($matchingFiles as $IDX => $fullPath){if(preg_match("/($lcSearch)%i",file_get_contents($fullPath),$matchingTitle)) { $lcTitle = strtolower($matchingTitle[1]);
RPK
+1  A: 

Assuming you did not change the $dirName assignment to omit server detail on a public posting, you should be setting that to the path to search. Since your use is pretty static, I'd suggest using the full path to the directory to open, e.g.

$dirName = '/home/myServer/public_html';

And of course make sure the permissions to all files it will search are compatible with the user your server is running as.

SleighBoy