끌어서 놓기를 통해 CSV 파일을 업로드하려고 시도하지만 Excel 파일과 같은 다른 파일을 업로드 할 때 경고 메시지가 표시되지 않습니다. 내가 도대체 뭘 잘못하고있는 겁니까?문자열의 마지막 몇자를 확인하십시오.
아래 기능을 호출합니다. 실제로 CSV 파일을 업로드했는지 확인해야합니다. 나중에 파일 확장명을 확인한 후 파일을 읽고이 (CSV) 파일에있는 데이터가있는 표를 채 웁니다. CSV 이외에 다른 업로드 유형이 없다는 것이 중요합니다.
if (!file.name.endsWith == ".csv") {
당신이 원하는 : 당신이 가지고
function handleFileSelection(evt) {
evt.stopPropagation(); // Do not allow the drop event to bubble.
evt.preventDefault(); // Prevent default drop event behavior.
var files = evt.dataTransfer.files; // Grab the list of files dragged to the drop box.
if (!files) {
alert("<p>At least one selected file is invalid - do not select any folders.</p><p>Please reselect and try again.</p>");
return;
}
// "files" is a FileList of file objects. Try to display the contents of each file:
for (var i = 0, file; file = files[i]; i++) {
if (!file) {
alert("Unable to access " + file.name);
continue; // Immediately move to the next file object.
}
if (file.size == 0) {
alert("Skipping " + file.name.toUpperCase() + " because it is empty.");
continue;
}
if (!file.name.endsWith == ".csv") {
alert("Skipping " + file.name.toUpperCase() + " because it is not a known text file type.");
continue;
}
startFileRead(file); // Asychronously fire off a file read request.
}
}
더 많은 컨텍스트와 코드를 제공해주십시오. 이 코드는 어디에서 호출하고 있습니까? 파일 배열은 어디에 정의되어 있습니까? – trincot