ACF 允许用户下载文件

问题描述 投票:0回答:1

我正在开发文件共享系统,用户可以将文件上传到他们的帐户。

现在上传部分可以工作了。我做到了,因此它根据 user_nicename 和 user_id 将文件上传到特定目录

示例:

https://site.nl/wp-content/uploads/useruploads/[user_nicename][user_id]/file.pdf

所以现在我正在考虑将用户单击文件时的 URL 重写为 download.php 文件,以检查用户是否是正确的用户。

.htaccess:

# Disable directory listing
Options -Indexes

# Rewrite requests to /wp-content/uploads/useruploads/ to download.php
RewriteRule ^wp-content/uploads/useruploads/(.*)$ /wp-content/themes/Child%20Theme/file-access/download.php?file=$1 [QSA,L]

现在主要问题是我收到权限错误

我的第二个问题是这是否安全。或者应该有更多的身份验证还是我应该以完全不同的方式进行此操作?

wordpress file download advanced-custom-fields uploading
1个回答
0
投票

在 useruploads 文件夹中添加 htaccess,将用户重定向到 download.php 文件,您可以在其中检查用户是否是正确的用户..

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*)$ /download.php?path=$1 [L]
© www.soinside.com 2019 - 2024. All rights reserved.