一旦我将新图像上传到wordpress, new directory
将在每月更改(like in aug /var/www/mysite/wp-content/uploads/2015/08)
时创建。它不包含index。php文件所以每个知道wordpress目录结构的人都可以直接访问这个文件夹。所以我想做的是创建一个index.php
文件一旦新的上传目录创建。所以我可以给wordpress
更好的安全性。非常感谢您的帮助
我以前遇到过这样的问题,我使用wordpress过滤器upload_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;
}
你需要使用。htaccess禁用目录索引
在/var/www/mysite/wp-content/
中创建新文件.htaccess
或
在现有的.htaccess
文件中添加以下行。
Options -Indexes