Jump to content

R code execution from PHP fails only in Browser and not in terminal


phpnewbie007

Recommended Posts

I am trying call an R batch file inside php script from browser. The R script basically generate an imgae and save in a folder. Unfortunately, I could call the R within php (means that no image is saved in  the folder) using BROWSER. But when I run the php script from the commadline, it works and image is saved in the folder.

<?php

exec("Rscript /var/www/html/phil/figs/map.R");

 ?>

Execuition of following R batch code and php codes work and save image in the specified folder from the terminal.

58A-UD3R:~$ php /var/www/html/phil/x.php

58A-UD3R:~$ Rscript /var/www/html/phil/figs/map.R

I totally in confusion why browser cannot successfully save image.  Or is there anythinng need to be change in server for generating image?

Anyone please help me for solving this probelm.

 

Thank You..

 

Link to comment
Share on other sites

Just to confirm, http://yourdomain.com/phil/x.php is the small PHP script you are showing, right?

 

Maybe read/write privileges?  What does the following give you?

<?php
echo ('Current script owner: ' . get_current_user().'</br>');

echo(exec("Rscript /var/www/html/phil/figs/map.R").'</br>');

shell_echo(exec("Rscript /var/www/html/phil/figs/map.R").'</br>');

?>
Link to comment
Share on other sites

I run with your test php file and it only displayed the user in browser (ie, Current script owner: 'myusername'). But not generated image in the folder. But when I run the same file from terminal, it generated image.

 

I have an HTML form and onclcik a button calls the x.php (which in turn expected to generate and save image). I call the file from url as 'http://localhost/phil/main.html'.

 

So is that a problem with permission?

 

Thanks...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.