asim Posted May 7, 2009 Report Share Posted May 7, 2009 Hi, Can anyone help me that how can i execute a bash script with php and how can i view the output of any txt file with the help of php? Regards Asim Quote Link to comment Share on other sites More sharing options...
BeeDev Posted May 7, 2009 Report Share Posted May 7, 2009 <?php // get contents of a file into a string $filename = "/path/to/your.txt"; $handle = fopen($filename, "r"); $contents = fread($handle, filesize($filename)); fclose($handle); echo "$contents"; Quote Link to comment Share on other sites More sharing options...
asim Posted May 7, 2009 Author Report Share Posted May 7, 2009 Thanks BeeDev I've tried it but it did not work. I'm getting the following error. Warning: fopen(c: mpp\htdocs est.txt) [function.fopen]: failed to open stream: Invalid argument in C:\xampp\htdocs\bash.php on line 6 Warning: filesize() [function.filesize]: stat failed for c: mpp\htdocs est.txt in C:\xampp\htdocs\bash.php on line 8 Warning: fread(): supplied argument is not a valid stream resource in C:\xampp\htdocs\bash.php on line 8 Warning: fclose(): supplied argument is not a valid stream resource in C:\xampp\htdocs\bash.php on line 10 Quote Link to comment Share on other sites More sharing options...
asim Posted May 7, 2009 Author Report Share Posted May 7, 2009 BeeDev , I've resolved this issue. I just removed the file complete path now its... $filename = "test.txt"; and the problem resolved. Quote Link to comment Share on other sites More sharing options...
tpattison Posted May 8, 2009 Report Share Posted May 8, 2009 The problem there was that you were using a local path. You should use the complete URL, such as http://www.host.com/path/to/file.txt, or a relative path as you have done in your last post. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.