我們在我們的服務器上保存 Flask 影像檔案時遇到問題。我們已經確保我們嘗試寫入的目錄具有寫入權限。我們使用了 chmod 影像 777。但我們得到“Permission Denied”。
我做了“chmod 777 images”目錄 ls -l 結果是 drwxrwxrwx 2 someuser someuser 4096 Jul 16 2021 images
提交檔案的表單結果:相同的回應:權限被拒絕
以下是我們擁有的相關代碼片段:
<form action="/someurl" method="post" enctype="multipart/form-data" id="workform">
<input type="file" name="photobefore” />
<input type="file" name="photoafter" />
<input type=“submit” />
</form>
服務器:
@main_blueprint.route(‘/someurl’, methods=['GET', 'POST'])
def workperformed():
message = “submitted”
before = ""
after = ""
try:
if len(request.files) > 0:
for name in request.files:
file = request.files[name]
if name == 'photobefore':
before = file.filename
if name == 'photoafter':
after = file.filename
if not file.filename == '':
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
except Exception as e:
message = "dir:" os.getcwd() " error:" str(e)
return message
結果:目錄:/錯誤:[Errno 13]權限被拒絕:'/home/someuser/public_html/mydefensiblespace.org/html/templates/static/images/20190721_184017_HDR.jpg'
uj5u.com熱心網友回復:
Web 服務器(假設 Ubuntu 上的 Apache 或 Nginx)需要是您保存影像的檔案夾的所有者
chown -R www-data:www-data /path/to/folder
我相信 Nginx 也需要該檔案夾是可執行的
chmod x /path/to/folder
此外,由于您的檔案夾路徑不在/var/www您的虛擬主機中,因此您需要一個指令
<VirtualHost *:80>
ServerName domain.com
# ...
<Directory /path/to/folder>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/461682.html
