Question

I have been trying for ages with all types of "file, file_get_contents, fopen, opendir and etc" to acomplish what I am triying to do, but just no can do for me, this goes beyong my understanding, sadly. But here I am to learn.

What I want to do? I work with LucidWorks, and I have built an Intranet search that searches the specific path given "C://example/example/..." and does a full text search through all the files. The output of the search on my intranet website is simple:

  • Document title
  • Body title with highlighted keyowrds
  • Path to the file

Now, that not being enough, my lazy fellow Companions would like to be able to click the Document title(which does indeed have a full path to the document behind it, just so you can picture it better "C:/Ex/ex/ex/docs/sap/text.txt(or any other termination)) and open it locally.

Here is the part of the code that I believe to be relevant for what I am trying to acomplish. The "solution" i have built in does not work, but it may give you an idea of what I am trying to accomplish here.

$searchParams = array(
                'hl' => 'true',
                'hl.fl' => 'body'
            );

            $response = $LWS->search($query, $offset, $limit, $searchParams);

            if ($response->response->numFound > 0) {

                foreach ($response->response->docs as $doc) {
                    ?>

                    <div id="resultbox">
                        <span id="resulttitle"> <?php echo "<a href={$doc->id}'>{$doc->title}</a><br />"; ?> </span> 

                        <?php
                        $content = (("{$doc->id}'>{$doc->title}"));
                        print_r( '<a href= ' . fopen(str_replace('%', ' ', $content), "r+") . '>Open File</a><br />');
                        ?>

                        <SPAN ID="copytext"  >
                            <?php echo substr($content, -100); ?> 
                            <br></SPAN>

                        <div id="sbody">
                            <?php
                            echo "..." . $response->highlighting->{$doc->id}->body[0] . "...<br /><br />";
                        }
                        echo '<br />';
                        return;
                    } else {
                        echo "No results for \"" . $query . "\"";
                        return;
                    }
                    ?>

There is a little bit more code above it, but it's irrelevant for the asked question.

So there you go folks, I am hoping for help, and to be able to learn something new :)

Was it helpful?

Solution

It looks as though you're trying to put the contents of the files into the href attribute of you anchor/link (<a>) tag.

What you need to be doing, instead, is using a url which links to the specified file. This could possibly look like this in your implementation;

print_r('<a href="' . $content . '">Open File</a><br />');

and the output would look something like;

<a href="file:/C:/path/to/your/file.txt">Open File</a><br />
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top