Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem opening a (remote) file

Status
Not open for further replies.

MorganGreylock

Programmer
Jan 30, 2001
223
US
I am working on a web-based (cgi) script that will allow easy searching through hundreds of "logs" that are mounted on an NFS share. I already have the search part working, which basically does a grep out of the log directory. It returns an array which I display to the webpage. I then want the user to be able to click on the log file to view the whole log file. Preferably this would happen in the browser without any extra clicking, or file-type additions, etc. (I'm assuming that the people who might be using this are grumpy and hate extra steps, which is mostly true.)

For example, On the webpage they might see this:
(searching for term 'sudo')
/nfs/share/logs/001.log: added user smith2 to sudo rule
/nfs/share/logs/004.log: sudo stopped working for
/nfs/share/logs/010.log: then I told them to use visudo but

So in other words, the grep only returns the lines where that search string exists, and I want them to be able to view the entire log file. I have tried (using substr) to make an html href link of the log name, and the link is created, but clicking on it gets no result whatsoever.
I've tried prepending a "file://", and that doesn't work either. I need to make sure that any computer they are using this page on will work, ie not only ones that can directly see the /nfs/share mounts. (Make sense?)

Any suggestions on what I might try to get this working?

Below is the code I'm working with right now:
Thanks!

Code:
for ($i=0; $i<$num_results; $i++)
{
        $logname = substr($output[$i], 0, 26);
        $logentry = substr($output[$i], 27);
        print "<a href=\"file:\/\/$logname\">$logname</a>";
        print " -- $logentry <BR>";
 }
Notice I escaped the slashes in file:// although I'm not sure thats necessary here. Still learning.
 
anchor tags are for oening URLs, they can be used to open files on local machines but not remote ones (unless they are files in a web accesible folder). You should use a query string argument, parse the query string and have the script open and disply the file. Something like:

<a href="yourscript.pl?file=$logname">$logname</a>



------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top