1

I uploaded an image file and copied it from temporary folder to a folder inside /var/www/. Then, tried to execute a python command via php where the exec() command is in the following format.

exec('python file.py $_FILES["file"]["name"]');

and even doing the following does not work,

exec('python file.py' + $_FILES["file"]["name"]);

In the python side, I am trying to read the filename and do some processing on it and save the image.

source = cv2.imread(sys.argv[1])
#some processing    
cv2.imwrite("upload/result.png", resultimage)

Note: The uploaded images are being shown as owned by www-data group after upload. I have added my user to the www-data group and have done the following as well.

sudo chown -R tilaprimera:www-data upload

sudo chmod -R g+s upload

where here upload is my folder storing the uploaded images. I have made the python script executable too,

sudo chmod +x script.py 

and also the script.py is perfectly running okay as

./script.py 

Why is the python script not executing via the php?

1 Answer 1

1

In the python script file, the directory change was done as

os.chdir('/var/www/upload')

and in the php side, I gave the full path for the python script to run

exec('python /var/www/upload/script.py ' . $_FILES["file"]["name"]);

This way, the problem got solved.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.