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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access Table Files via PHP 1

Status
Not open for further replies.

douglagm

MIS
Oct 24, 2003
19
ZA
Hi,
Hopefully someone out there can help me ?
I have got table files that I can only access through the program that creates them, but I want a web-interface so that others can see the info.

I can open the .REC files in Notepad, so I would imagine they are plain text files. The .TBL cotains ASCII characters when open through Notepad.

So, does anyone have any ideas on how I can get PHP to access these files (.TBL and .REC)

Thanks
 
<?php
// get contents of a file into a string
$filename = &quot;/usr/local/something.rec&quot;;
$handle = fopen ($filename, &quot;r&quot;);
$contents = fread ($handle, filesize ($filename));
fclose ($handle);
?>

see if that works - if the files are not within the web or server root u may have problems with PHP being able to access them b/c of permissions.

Rocco is the BOY!!

SHUT YOUR LIPS...
ROCCOsm.gif
 
I have been trying the script. Keep on getting &quot;failed to open stream: Permission denied&quot;. I even install apache and php on a w2k server and edited the php.ini and used the include_path, but still the same error. Is there another another file I need to edit inorder for PHP to have access to the directory ?
 
You need to make sure that the web server has read access top the folder and files. Check as what user the web server runs and apply read privileges to the necessary folders and files.
 
I eventually got it right. I can now read the info of a table file in the web-browser, but now I want to select text from the table file. The text in the file is as follows
***** Computer Associates ALERT Event Log File *****



Application : ARCserve

Priority : Warning

Action : Broadcast,AlphaNumerical Pager,EMail,Trouble Ticket,Event Log,SNMP,Notes,Unicenter TNG,SMTP



Message :ARCALERT: [JobID:0 ] SPNNIS09: BrightStor ARCserve: E1145 Media write error - Drive or Media Failure.

From :ARCALERT
I want to be able to extract the server name (&quot;SPNNIS09&quot;) and the error code.
 
You would accomplish that by using regular expressions.
First you need to establish a specific pattern that you want to match. Is the message line always built the same?
If so, we can go from there using preg_match()

If you need help with the regexp, let us know.
 
I have got it working, got so far as to create a csv file with : server_name,date,backup_message. The script access only one file though, but there are alot of files as each backup message is contained in a file. So I need to have a loop that scans all .REC files and saves the file name in an array. Then run the script to extract the server_name, date and backup_message for each file.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top