I need to allow a user to upload 3 files.
The files should be named as:
userName.jpg
userName1.jpg
userName2.jpg
Currently user can have one file userName.jpg
What is the best way to handle the naming of those files?
Shall I put all allowed names into an array and check against it when I allow file upload? Say, user has userName.jpg and userName2.jpg but deleted userName1.jpg.
$namesArray = array(userName.jpg, userName1.jpg, userName2.jpg);
I would need to count how manu files are already uploaded and then check their names by using something like:
$existingFiles = array(userName.jpg, userName2.jpg);
$countFiles = count($existingFiles);
if ($countFiles > 0) {
foreach ($namesArray as $key) {
if (!in_array($key, $existingFiles )) {
$newName = $key;
}
}
Sounds about right, but I'm not quite sure.