我的权限有问题。我正在Apache2 / var / www / html / project上使用CGI运行.py程序,在.py程序上,我尝试在我得到的/opt/image.png中打开文件:
PermissionError: [Errno 13] Permission denied: '/opt/image.png
Apache2配置:
<VirtualHost *:80>
ServerName localhost
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
<Directory /var/www/html/project>
Order Allow,Deny
Allow from all
Options +ExecCGI
AddHandler cgi-script .py
</Directory>
<Directory "/opt">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
代码,我从外部获取POST路径:
#!/usr/bin/python3
# -*- coding: UTF-8 -*-# enable debugging
print("Content-Type: text/html;charset=utf-8")
print()
import cgitb, cgi
cgitb.enable()
import PIL
form = cgi.FieldStorage()
file = form.getvalue('file')
imopen = Image.open(file)
我尝试将修饰符更改为777,所有者仍为root,但我仍然无法访问并且权限被拒绝。我认为问题是我无法从/ var访问/ opt?有什么线索吗?谢谢。