我试图通过将文件夹名称作为URL参数来调用目录的内容来调用php函数。我遵循了stackoverflow上提供的其他一些示例,并且能够调用php函数并确定我因为输出的echo语句而到达内部代码。
url似乎编码正确,因为当我在php函数中显示路径信息时,所有路径都会检出。
www.mysite.com/php/genListing.php?function=genListing&folder=wp-content/uploads/myfiles
对is_readable()的检查似乎失败了。我已检查该目录的文件权限,并且所有用户都具有读取权限。任何人都知道问题可能是什么?
genListing.php
if ( ! empty( $_GET['function'] ) && function_exists( $_GET['function'] ) ) {
if ( $_GET['function'] == 'genListing')
{
$atts = $_POST;
genListing( $atts );
}
}
function genListing( $atts ) {
$folder = $_GET[ 'folder' ];
if ( ! empty( $_GET['title'] ) ) {
$title = $_GET['title'];
}
else
{
$title = 'Directory Listing';
}
echo "<p>Made it inside genListing(): " . $folder . "</p>";
$fullFolderPath = trailingslashit( WP_INSTANCE_HOME ) . $folder;
echo "<p> Trying: " . $fullFolderPath . "</p>";
// bad folder check
if ( empty( $folder ) || ! is_readable( $fullFolderPath ) ) {
echo "<p>The folder selected was not valid.</p>";
return 'The folder selected was not valid.';
}