I was hoping, via glob of a local directory, to take the base file names in that directory and load it into a mysql table. Then having a double select reading that table to choose which files to do load data infile. The second part is fine. The first is being problematic and I think I have my head in a box. It works fine in development because client/server same machine. Can I read these files names on my client and have it feed into a table server-side? Would have thought foreach (glob([mydir]."*.csv") as $filename) { would have read with [mydir] being client directory. But no. Thoughts?
Maybe this will help… little script I was playing with a few days back… needs finishing, but it may help you:
// PHP script to scan directories and files from root and gather metadata
function scanDirectories($rootDir, &$allData) {
// Attempt to open the directory
$dir = @opendir($rootDir);
if (!$dir) {
echo "Failed to open directory: " . $rootDir . "\n";
return; // Exit the function if the directory can't be opened
}
while(false !== ($file = readdir($dir))) {
if ($file === '.' || $file === '..') continue;
$fullPath = $rootDir . '/' . $file;
try {
if (is_file($fullPath)) {
$fileInfo = array(
'name' => basename($fullPath),
'type' => mime_content_type($fullPath),
'size' => filesize($fullPath),
'created_at' => filectime($fullPath),
'updated_at' => filemtime($fullPath)
);
array_push($allData['files'], $fileInfo);
} elseif (is_dir($fullPath)) {
array_push($allData['folders'], $fullPath);
scanDirectories($fullPath, $allData); // Recursive call
}
} catch (Exception $e) {
echo "Error accessing file or directory: " . $fullPath . "\n";
}
}
closedir($dir);
}
// Initialize the data storage array
$allFilesAndFolders = array('files' => array(), 'folders' => array());
// Start scanning from the root directory
//scanDirectories('/path/to/your/root', $allFilesAndFolders);
scanDirectories('C:/Program Files/NetMake/v9-php81/wwwroot/scriptcase/', $allFilesAndFolders);
// Print the collected file metadata
foreach ($allFilesAndFolders['files'] as $file) {
echo "File Name: " . $file['name'] . "\n";
echo "File Type: " . $file['type'] . "\n";
echo "File Size: " . $file['size'] . " bytes\n";
echo "Created At: " . date("Y-m-d H:i:s", $file['created_at']) . "\n";
echo "Updated At: " . date("Y-m-d H:i:s", $file['updated_at']) . "\n\n";
}
I’ll check it out. Thanks.