Jump to content

Recommended Posts

Posted

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

Posted
<?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";

Posted

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

Posted

BeeDev ,

 

 

I've resolved this issue. I just removed the file complete path now its...

 

 

$filename = "test.txt";

 

 

and the problem resolved.

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...