File not created (Linux-PHP-C++) - php

I am trying to save a file to the current directory in Linux and then display it on a webpage. Currently I run a C++ executable from a php script with the following code
exec("/var/www/html/radsim/plotFluence $rMin $rMax $zMin $zMax $lum $graphStyle $basepath[$path]", $return);
When I run the executable from the console in Linux the file is created fine, the problem arises when I try from within the php; the file is simply not in the directory . The user inputs values and the executable is run but no file is made. The C++ looks like this
canvas->Print(("/var/www/html/radsim/"+histoName+_FileFormat).c_str());
The permisions are set to 777. In addition, on another PHP script, I use fopen("data.txt", 'w') or die() to create a text file, but it always dies.

Seems like a sandbox. There must be a php config option - best to start here: http://php.net/manual/en/configuration.changes.php

Related

file_get_contents failure on windows

I have a PHP CLI application that creates a file with file_put_contents then listens for changes to that file. If the filemtime changes then I try to get the content with file_get_contents. It often fails to retrieve the contents on windows. This baffles me. How is it possible that a process that creates the file cannot open the file?
I even ran icacls on the folder that the file is in and it still fails to have access to read the file that it created.
icacls.exe 'MYFOLDER' /grant MYUSER:(OI)(CI)F /T
Can someone please enlighten me on how to insure a PHP process can read a file it created?

Python file will not run from php

I have a PHP file on my web server that is supposed to call a python script (same folder) that writes out to a file and then get its contents and displays the data.
The PHP file is called q.php
it contains
<?php
$tmp = exec("trivia.py");
sleep(4);
$homepage = file_get_contents('./testfile.txt', true);
echo $homepage + '<p>exec ret:' + $tmp;
echo exec("whoami");
?>
This file calls a trivia.py which writes out a file ("./testfile.txt") and then php gets the data from the file and displays it. I added a variable to see if the exec is working and it returns 0. The PHP server is being executed by user http.
now for trivia.py, I have the following line at the top of the file
#!/usr/bin/env python
and it executes perfectly fine when I SSH into the server. From SSH I run the script and it creates the file specified above and the web page works fine. However, if I used the PHP file to create it, it will not work from the web.
I am pretty sure this has something to do with permissions somewhere but I am not that great on permissions for Linux.
SYSTEM INFO: Synology Diskstation, DSM5, PHP5, Python 2.7
EDIT:
trivia.py currenlty has 777 as permissions with admin owner and group users
When running a file via exec you need to provide the full path to the file, it doesn't matter if the file is in the same directory.
Please try it with (assuming the file is in /var/www/public)
exec('/var/www/public/trivia.py');
For Windows User -
Problem was resolved here PHP exec python
I suggest to replace $tmp = exec("trivia.py"); for this one
$tmp = exec("C:\\Python27\\python.exe trivia.py");
// Add your python.exe route before the file
Hope it works!!

Run a php script via Windows Batch File - not working in Task Scheduler only

My .bat files do not work with Task Scheduler.
For testing purposes, I created an extremely simple, one line .bat file:
php E:\POC\route.php
{the router.php file contain some file operation}
If I run this file by double-clicking it, it works correctly and Returned The Expected Output
But if I create a task to run this very same file, the text file is NOT created. The History log for the task says that the task was started and completed successfully yet no text file is created.
Note: Already i set the environment variable for php ("E:\Php")
Any thoughts? Thanks.

Windows Batch File To Execute PHP Accessing mySQLi Database

I am writing a windows batch file that needs to execute a PHP file which fetches data from a backend and inserts into mysql database.
Below is the code I used and it is working but it will open the browser.
#ECHO OFF
START http://localhost/test.php
How do I ensure that the browser is not invoked when START is executed? I have tried to put /B at the back but it not working.
I have also tried the following but it is not working at all and nothing gets inserted.
#ECHO OFF
php.exe -f "C:\wamp\www\test.php"
The simple answer is that php files are set up to open with your default browser, when you open the php file, it will open with that browser.
If you want to view the contents of the file in cmd instead you can use
type test.php

PHP script can't open a file when called from a perl script

I have an interesting situation where I have a perl watcher script (using Linux::Inotify2) watch for files to be dropped in a certain directory, then hand them off to a PHP script for processing. The watched directory and the files in it are not owned by the user the watcher script is running under, but the entire directory tree the files are being dumped in are rwxr-xr-x and the file is world readable.
Here's my delemma. The PHP script cannot open a file handle on the file passed to it when called from the perl script using system(), exec() or ``. However, the PHP script can open a file handle on the same file when the script is run manually from the command-line using the same effective user.
Anyone have any ideas why this would be the case?
Your fopen() calls probably rely on relative paths that break when the working directory change.

Categories