누군가가 Excel (xls 및 xlsx) 파일 확장명을 바꾸면 (why :-() 이유를 묻지 마십시오. 확인해야합니다. 유효성. 내가 MIME 유형과 그 작동하지를 사용하고 (즉, 유효한 엑셀 파일이 여전히 경우). 난 아무것도 실종? ASP.NET 확장명과 관계없이 파일 형식의 형식을 확인하는 방법
const string excel2007MimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
const string excel2003MimeType = "application/vnd.ms-excel";
string excelExtention = string.Empty;
excelExtention = System.IO.Path.GetExtension(myFilePath.PostedFile.FileName).ToLower();
string mimeType = myFilePath.PostedFile.ContentType;
Response.Write("mime type" + mimeType + Environment.NewLine);
if(
(
!(excelExtention == ".xls" && mimeType == excel2003MimeType)
||
!(excelExtention == ".xlsx" && mimeType == excel2007MimeType)
)
)
{
Response.Write ("only excel file is permitted");
}
내가 파일을 XLSX 및 업로드 할 JPG 파일의 이름을 바꿉니다. 나는 인쇄 할 경우 변수 마임은,이 값은. 나는 확실히 "응용 프로그램/vnd.openxmlformats-officedocument.spreadsheetml.sheet"아니다 이유 내용이 엑셀 파일이 아니기 때문에. 그것의 이미지.
"작동하지 않음" 정확히 작동하지 않는 것은 무엇입니까? – Oded
사용자가 파일을 업로드하면 확장명과 사용자 레지스트리에 의해 MIME 유형이 설정됩니다. 유효한 파일을 나타내지는 않습니다. 잘못된 접근이기 때문에 효과가 없습니다. –
@Kieren, 감사합니다. 나는 그렇게 생각했다. 더 나은 접근 방법이 있습니까? –