How to import directory and echo the filename ?

I want to import the directory without set the import location , because i have many directory to import.

$log_directory = '/xampp/htdocs/mydoc';

$results_array = array();

if (is_dir($log_directory))
{
        if ($handle = opendir($log_directory))
        {
                //Notice the parentheses I added:
                while(($file = readdir($handle)) !== FALSE)
                {
                        $results_array[] = $file;
                }
                closedir($handle);
        }
}

//Output findings
foreach($results_array as $value)
{
    echo $value . '<br />';
}

Open in new window


$log_directory = '/xampp/htdocs/mydoc';
I dont wanna set path like this .. izit posible or not ? because i lazy set again and again to import different directory
Yong Scott Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Julian HansenCommented:
Upload to where?

You are using server side code - which means the directory must be on the server - where are you wanting to upload it to and how?
0
Yong Scott Author Commented:
No I want to list down all the file name i uploaded without setting the path $log_directory = '/xampp/htdocs/mydoc';
0
Yong Scott Author Commented:
<?php
include 'config.php';

if(isset($_POST['btn-upload']))
{  


$targetDir = "uploads/";
$fileName = $_FILES['file']['name'];
$targetFile = $targetDir.$fileName;


//Show filename with file extension
 print $fileName . "\n";
}

?>

Open in new window


I found this can but only single file will display ~
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Julian HansenCommented:
To upload multiple files you need
a) A file input control with attribute multiple and a name specificying an array
<input type="file" name="files[]" multiple>

Open in new window

This will allow for multiple selection of files on the client which will then be sent as an array of files to the server.

b) On the server you need to retrieve the array of files

$files = $_FILES['files']

Open in new window


And then

c) You need to loop over that array and process each file in turn
$targetDir = "uploads/";
foreach($files['name'] as $key => $name) {
    $file = $files['tmp_name'][$key];
    $target = $targetDir  . "/" . $name;
    if (is_uploaded_file($file)) {
       move_uploaded_file($file, $target);
    }
}

Open in new window


EDIT:
Remember to add the form enctype attribute to "multipart/form-data"
<form action="..." method="post"  enctype="multipart/form-data">

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Yong Scott Author Commented:
Notice: Undefined variable: files in C:\xampp\htdocs\db_v3\upload.php on line 8

Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\db_v3\upload.php on line 8

Error

$targetDir = "uploads/";
foreach($files['name'] as $key => $name) {
    $file = $files['tmp_name'][$key];
    $target = $targetDir  . "/" . $name;
    if (is_uploaded_file($file)) {
       move_uploaded_file($file, $target);
    }
}
0
Julian HansenCommented:
Where is $files declared?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Databases

From novice to tech pro — start learning today.