I am trying to list the contents of a directory by passing a folder name as a URL parameter to invoke a php function. I followed some other examples provided on stackoverflow and have been able to get the php function invoked and am certain I am reaching the code inside because of the echo statements that are output.

The url seems to be encoded correctly because when I display the path info inside the php function all the paths check out.

www.mysite.com/php/genListing.php?function=genListing&folder=wp-content/uploads/myfiles

The check on is_readable() appears to be failing. I have checked the file permissions for that directory and all users have read access. Anybody have any idea of what the problem might be?

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.';
}

Read more here: Passing a folder name through a url as a parameter to invoke a php function


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: