I need to be able to assign a name to a file from the list of available names.
Maximum number of files is 5 (in this example).
So I need to get the names of the existing files first then compare it against the list of all available names.
If I have less then max files number I need to pick the first available name to use.
I think I need to use arrays for this:
// create array of existing files>>
$FILES = glob($targetDirName."*.mp3");
foreach($FILES as $key => $file) {
$FILE_LIST[$key]['name'] = basename(substr( $file, ( strrpos( $file, "\\" ) +1 ) ), ".mp3");
$existingNamesString .= $FILE_LIST[$key]['name'].', ';
}
$existingNamesString = rtrim($existingNamesString, ', ');
$existingNames = explode(", ", $existingNamesString);
// create array of existing files<<
// create array of allowed file names >>
$maxVO = 5;
$n = 1;
while ($n <= $maxVO) {
$allowedNamesString .= $filename.$n.', ';
$n++;
}
$allowedNamesString = rtrim($allowedNamesString, ', ');
$allowedNames = explode(", ", $allowedNamesString);
// create array of allowed file names <<
$avail_Names = array_diff($allowedNames, $existingNames);
Is this correct approach? How do I get the first available file name?
I tested this code but I keep seeing repeat values...