I tried wrapping my code in a for loop as outlined above and I couldn't get it to work. So I'm trying Plan B.
$fileTypeExt = pathinfo($path1,PATHINFO_EXTENSION);
echo $fileTypeExt . "<br/>";
$fileTypeExt2 = pathinfo($path2,PATHINFO_EXTENSION);
echo $fileTypeExt2 . "<br/>";
// Allow certain file formats
if($fileTypeExt == "txt" || $fileTypeExt == "doc" || $fileTypeExt == "pdf") {
echo "Your file extensions are allowed.";
$uploadOk = 1;
}
else {
echo "Sorry, only TXT, PDF, & DOC files are allowed. <br />";
$uploadOk = 0;
}
// Allow certain file formats
if($fileTypeExt2 == "txt" || $fileTypeExt2 == "doc" || $fileTypeExt2 == "pdf") {
echo "Your file extensions are allowed.";
$uploadOk2 = 1;
}
else {
echo "Sorry, only TXT, PDF, & DOC files are allowed. <br />";
$uploadOk2 = 0;
}
Plan B works, but I was wondering if there's a more compact way to write this. I frequently get tripped up on how to extend working logic
to additional cases. For instance, do I need a $fileTypeExt and $fileTypeExt2 variables? Same with $uploadOk and $uploadOk2? I guess a switch
statement would work if I had many cases.
Perhaps one answer is to make a giant conditional, e.g.,
if($fileTypeExt == "txt" || $fileTypeExt == "doc" || $fileTypeExt == "pdf") && ($fileTypeExt2 == "txt" || $fileTypeExt2 == "doc" || $fileTypeExt2 == "pdf")...but I didn't know if that was the best approach. It would remove the need for two status variables ($uploadOk and $uploadOk2).
Thanks in advance for your ideas.