Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9124427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:34:10+00:00 2026-06-17T06:34:10+00:00

I have the following code in my PHP file – initializes $uploaded_files variable and

  • 0

I have the following code in my PHP file – initializes $uploaded_files variable and then calls getDirectory (also listed below).

Now if I do a vardump($uploaded_files) I see the contents of my variable, but for some reason when I call <?php echo $uploaded_files; ?> in my HTML file I get a message stating “No Files Found” – am I doing something incorrect?

Can someone assist? Thank you.

/** LIST UPLOADED FILES **/
$uploaded_files = "";

getDirectory( Settings::$uploadFolder );

// Check if the uploaded_files variable is empty
if(strlen($uploaded_files) == 0)
{
    $uploaded_files = "<li><em>No files found</em></li>";
}

getDirectory Function:

function getDirectory( $path = '.', $level = 0 )
{ 
    // Directories to ignore when listing output. Many hosts 
    // will deny PHP access to the cgi-bin. 
    $ignore = array( 'cgi-bin', '.', '..' ); 

    // Open the directory to the handle $dh 
    $dh = @opendir( $path ); 

    // Loop through the directory 
    while( false !== ( $file = readdir( $dh ) ) ){ 

        // Check that this file is not to be ignored 
        if( !in_array( $file, $ignore ) ){ 

            // Its a directory, so we need to keep reading down... 
            if( is_dir( "$path/$file" ) ){ 

                // We are now inside a directory
                // Re-call this same function but on a new directory. 
                // this is what makes function recursive. 


      getDirectory( "$path/$file", ($level+1) );   
        } 

        else { 
            // Just print out the filename 
            // echo "$file<br />"; 
            $singleSlashPath = str_replace("uploads//", "uploads/", $path);

            if ($path == "uploads/") {
                $filename = "$path$file";
            }
            else $filename = "$singleSlashPath/$file";

            $parts = explode("_", $file);
            $size = formatBytes(filesize($filename));
            $added = date("m/d/Y", $parts[0]);
            $origName = $parts[1];
            $filetype = getFileType(substr($file, strlen($file) - 4));
            $uploaded_files .= "<li class=\"$filetype\"><a href=\"$filename\">$origName</a> $size - $added</li>\n";
            // var_dump($uploaded_files);
        } 
    } 
} 

// Close the directory handle
closedir( $dh ); 
} 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T06:34:12+00:00Added an answer on June 17, 2026 at 6:34 am

    You either need to add:

    global $uploaded_files;
    

    At the top of your getDirectory function, or

    function getDirectory( &$uploaded_files, $path = '.', $level = 0 )
    

    Pass it by reference.

    You could also make $uploaded_files the return value of getDirectory.

    More reading about globals and security: http://php.net/manual/en/security.globals.php

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: if (include_once(dirname(__FILE__).'/file.php') || include_once(dirname(__FILE__).'/local/file.php') ) { This causes an
In PHP I have the following code that gets a file submitted through CGI:
I have the following lines of php code which should rename a file which
I have tried the following code in single.php file in wordpress. I used these
I have the following code which works perfectly fine in my php file and
I have the following code in my Drupal 7 template.php file: function mytheme_preprocess_views_view__videos__videos(&$vars) {
I have a view file update.php and contains the following code: php foreach ($record
In my php file I have the following code //create SQL to select schedule
I have the following code in my .htaccess file RewriteEngine on RewriteRule ^thumbnail/(.*).png thumbnail.php?url=$1
I have the following code stored in a file called index.php. <?php file_put_contents(date('Y-m-d-H-i-s', time())

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.