Validate uploaded file extension

后端 未结 2 1044
逝去的感伤
逝去的感伤 2021-01-25 04:47

Uploading files works fine but now I\'m trying to validate file extensions and looks like there\'s some interference between FileUpload1 and FileUpload2

2条回答
  •  迷失自我
    2021-01-25 05:15

    are you uploading both files at the same time, or only one at a time? if it is only one at a time, then one of those values is always going to be false.

    You are also adding a period in front of your validPhotoFile and validPDFFile, change your code like this.

    for (int i = 0; i < validPhotoFile.Length; i++)
    {
        if (photoExt == validPhotoFile[i]) // remove the period here it is already in your variables above
        {
            isValidPhotoFile = true;
            break;
        }
    }
    
    for (int i = 0; i < validPDFFile.Length; i++)
    {
        if (pdfExt == validPDFFile[i]) // remove the period here it is already in your variables above
        {
            isValidPDFFile = true;
            break;
        }
    }
    

提交回复
热议问题