Yong Scott
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 />';
}
$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
ASKER
No I want to list down all the file name i uploaded without setting the path $log_directory = '/xampp/htdocs/mydoc';
ASKER
<?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";
}
?>
I found this can but only single file will display ~
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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?
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?