让隐藏不会禁用所有文件夹和.tmp文件除PDF文件(contaned在该文件夹)文件夹、文件、contaned、tmp

2023-09-02 00:44:48 作者:谁惊艳了谁的时光

如何使隐藏不禁所有子文件夹和.tmp文件(如下图),并只显示.pdf文件给用户, 我组成的目录结构中的动态创建(即prevents我editng的在.htaccess新的文件夹名称),如子文件夹:

How to make hide not disable all child folders and .tmp files (below) and show only .pdf files to user, my directory structure composed of dynamically created (that prevents me of editng in .htaccess for new folder names) child folders like:

Parent->
  Child1->
  Child1.tmp,Child1.pdf

  Child2->
  Child2.tmp,Child2.pdf

  and so on...

,你可以在上面看到禁用文件夹会导致的访问被拒绝的PDF文件。 因此,当用户创建一个名为F1的文件夹并上传PDF文件,然后命名包含该PDF文件+相同名称的PDF文件的.tmp F1一个新的子文件夹的创建,进一步当任何用户想要搜索和下载公共pdf文件,他应该只看到(和访问只)该.pdf文件没有它存在的文件夹,而不是TMP。 那么,有没有这样做(特别是使用的.htaccess)中的任何羊城通 ??

as you can see above disabling folders will cause access denied to pdf files. Thus when user creates folder named F1 and upload pdf file, then a new child folder named F1 containing that pdf file + .tmp file of same name as pdf are created, further when any user wants to search and download that public pdf file, he should see only (and access only) that .pdf file not the folder in which it exists and not the tmp. So is there any secure way of doing that (specially using .htaccess).??

推荐答案

您可以有这样的规则,在你的 DOCUMENT_ROOT / MY_PROJECT /我/的.htaccess 文件:

You can have this rule in your DOCUMENT_ROOT/my_project/i/.htaccess file:

RewriteEngine On
RewriteBase /my_project/i/

RewriteRule ^([^/]+)(?:/.+?.tmp|/)$ - [F,NC]

请务必使此第一个规则。

Make sure to make this your first rule.