Link to home
Start Free TrialLog in
Avatar of Yong Scott
Yong ScottFlag for Malaysia

asked on

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
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

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?
Avatar of Yong Scott

ASKER

No I want to list down all the file name i uploaded without setting the path $log_directory = '/xampp/htdocs/mydoc';
<?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 ~
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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);
    }
}
Where is $files declared?