Php 增强wordpress安全性以直接访问文件夹

Php 增强wordpress安全性以直接访问文件夹,php,wordpress,security,Php,Wordpress,Security,一旦我将新图像上传到wordpress,一个月的变化就会创建新的目录(如8月/var/www/mysite/wp content/uploads/2015/08)。它不包含index.php文件,因此每个知道wordpress目录结构的人都可以直接访问该文件夹。因此,我要做的是在创建新的上载目录后创建一个index.php文件。因此,我可以为wordpress设置更好的安全性。感谢您的帮助您需要使用.htaccess禁用目录索引 在/var/www/mysite/wp content/ 或 将以

一旦我将新图像上传到wordpress,一个月的变化就会创建新的目录(如8月/var/www/mysite/wp content/uploads/2015/08)。它不包含index.php文件,因此每个知道wordpress目录结构的人都可以直接访问该文件夹。因此,我要做的是在创建新的上载目录后创建一个
index.php
文件。因此,我可以为
wordpress
设置更好的安全性。感谢您的帮助

您需要使用.htaccess禁用目录索引

/var/www/mysite/wp content/

将以下行添加到退出的
.htaccess
文件中

Options -Indexes 

您需要使用.htaccess禁用目录索引

/var/www/mysite/wp content/

将以下行添加到退出的
.htaccess
文件中

Options -Indexes 

我以前遇到过这样的问题,我用wordpress过滤器
upload\u dir
修复了它

请将此代码添加到
function.php
文件中,并将图像上传到媒体中

add_filter('upload_dir', 'sofg_secure_dir');
function sofg_secure_dir( $param ){ 
   $filename = $param['path'].'/index.php';
    if (!file_exists($filename)) {
            $myfile = fopen($filename, "w") or die("Unable to open file!");
            $txt = "<?php // silence is golden  ?>";
            fwrite($myfile, $txt);
            fclose($myfile);
    }
    return $param; 
}
add_filter('upload_dir'、'sofg_secure_dir');
函数sofg_secure_dir($param){
$filename=$param['path']./index.php';
如果(!file_存在($filename)){
$myfile=fopen($filename,“w”)或die(“无法打开文件!”);
$txt=”“;
fwrite($myfile,$txt);
fclose($myfile);
}
返回$param;
}

我以前遇到过此类问题,我使用wordpress filter
upload\u dir
修复了它

请将此代码添加到
function.php
文件中,并将图像上传到媒体中

add_filter('upload_dir', 'sofg_secure_dir');
function sofg_secure_dir( $param ){ 
   $filename = $param['path'].'/index.php';
    if (!file_exists($filename)) {
            $myfile = fopen($filename, "w") or die("Unable to open file!");
            $txt = "<?php // silence is golden  ?>";
            fwrite($myfile, $txt);
            fclose($myfile);
    }
    return $param; 
}
add_filter('upload_dir'、'sofg_secure_dir');
函数sofg_secure_dir($param){
$filename=$param['path']./index.php';
如果(!file_存在($filename)){
$myfile=fopen($filename,“w”)或die(“无法打开文件!”);
$txt=”“;
fwrite($myfile,$txt);
fclose($myfile);
}
返回$param;
}

如果我这样做,则不会打开我的site@bhaveshvala上述解决方案不会影响您的站点。它只是简单地禁用目录列表。请您解释一下我怎么做,因为我没有完全的服务器访问权限。?@bhaveshvala您只需要ftp访问就可以了。在您的文件夹
/var/www/mysite/
中必须有名为
.htaccess
的文件。只需下载此文件并将
Options-index
添加到现有的.htaccess文件中。@bhaveshvala我很高兴它能为您工作。它的简单而快速的解决方案:)如果我这样做,那么就不会打开我的site@bhaveshvala上述解决方案不会影响您的站点。它只是简单地禁用目录列表。请您解释一下我怎么做,因为我没有完全的服务器访问权限。?@bhaveshvala您只需要ftp访问就可以了。在您的文件夹
/var/www/mysite/
中必须有名为
.htaccess
的文件。只需下载此文件并将
Options-index
添加到现有的.htaccess文件中。@bhaveshvala我很高兴它能为您工作。其简单而快速的解决方案:)从媒体上传任何图像,这样我的上传过滤器将被执行并创建index.php文件..从媒体上传任何图像,这样我的上传过滤器将被执行并创建index.php文件。。