I'm trying to figure out how I can re-use my $php\_file & doc\_file variables outside of my if statements?

Here's the scenario...

Generally for every file(.pdf/.doc/whatever) gets uploaded to the file path, there's also a php file that gets created as well. Here's a quick breakdown below.

> 
> myuploaded\_file.pdf
> 
> 
> myuploaded\_file.pdf.php
> 
> 
> 

Basically I'm trying to distinguish these files into their own defined variables, so my end-results would be as followed...

```
$doc_file=myuploaded_file.pdf

$php_file=myuploaded_file.pdf.php

```

And then basically run it in a loop for all of the uploaded files in that directory.

I have it fairly close to where I need it to be i.e. the variables are defined properly when being utilized within each of the if statements, however I'm seeing how I can use these variables outside of the if statements, now that the files are properly defined into their own variables based on the file types.

I can't even echo these variables outside of the if statements without running into "doc\_file or php\_file variable is not defined". I tried tinkering with setting global variables, var\_dump's, etc. but I'm still having no luck. Any ideas?

UPDATED CODE

```
<?php
// Open the folder
$f_path = "files/News/"; 

$dir_handle = @opendir($f_path) or die("Unable to open $f_path"); 

// Loop through the files 
while ($file = readdir($dir_handle)) { 
    $doc_file="";
    $php_file="";

    // Verify files
    if($file == "." || $file == ".." ) {
        continue;
    }
    // Validate if the file is appended with .php
    if (strpos($file , '.php') !==false) {
        $php_file = $file;
        //echo "PHP: $php_file <br />";
    }
    // Print out the files that don't contain the .php extension
    else {
        $doc_file = $file;          
        //echo "PDF: $doc_file <br />";
    }
echo "PHP: $php_file <br />";
echo "PDF: $doc_file <br />";
}

// Close 
closedir($dir_handle);

?>

```

RESULTS FROM THE LOOP

I'm seeing how I can avoid the blank values returning in my results?

PHP:

PDF: uploaded\_file1.pdf

PHP: uploaded\_file1.pdf.php

PDF:

PHP:

PDF: uploaded\_file1.pdf

PHP: uploaded\_file1.pdf.php

PDF: