I have a PHP script that will create and append data to a text document. The script will then execute a python script that will read over that document, and move create a different document else where on the raspberry pi. I have been looking for the past several hours at different solutions, and they all seem to boil down to permissions. Based on what I have found, I have set the following:
-rwxrwxrwx 1 www-data www-data 314 Jan 9 16:09 AlbumString.py
-rwxrwxrwx 1 www-data www-data 74 Jan 9 21:31 display.txt
The AlbumString.py is the python script, the display.txt is where the PHP file rights to, and the Python script reads from. Further research somone suggested looking at the error logs for apache. When I looked at this I saw that I was getting a permission error:
Traceback (most recent call last):
File "AlbumString.py", line 13, in <module>
display = open('/media/pi/external/Photos/' + templist.pop(0),'a')
PermissionError: [Errno 13] Permission denied: '/media/pi/external/Photos/Erik.txt'
My python code will create or append a file if it already exists. In the case of running this iteration, the file Erik.txt did not exist, so it would have had to create it. The code for AlbumString.py:
#!/usr/bin/python
import sys
import json
import base64
album = open('/var/www/html/uploads/display.txt')
templist = []
a= 0
for x in album:
templist.append(x.rstrip('
'))
album.close()
display = open('/media/pi/external/Photos/' + templist.pop(0),'a')
for x in templist:
display.write(x+'
')
display.close()
The PHP code that I am using to call the python script:
fclose($fh);
$testing = shell_exec("python3 AlbumString.py");
if(!$testing){
echo "You are a failure!<br>";
} else {
echo "You are a genius<br>";
}
echo "end of document";
}
I have also added www-data to my sudoers file, which is not suggested but that I would give it a chance, and nothing has worked. The PHP correctly writes to the file, and if I call the python script from a console, that properly executes as well.