사용자가 업로드 한 파일의 이름을 표시하려고합니다. 파일은 성공적으로 업로드되지만 자바 스크립트에서는 아래 메시지를 계속 표시합니다.파일 이름이 표시되지 않습니다.
파일 (정의되지 않음)이 성공적으로 업로드되었습니다.
파일 이름을 표시해야 할 때 계속 표시되지 않습니다. 왜 이런거야? 현재 일어나고있는 일은 사용자가 파일을 업로드하고 파일이 "ImageFiles"폴더에 업로드되며 업로드가 완료되면 아래의 javascript 함수는 성공적으로 업로드 된 파일의 이름을 나타내는 메시지를 표시합니다.
다음function stopImageUpload(success){
function handleFileSelect(evt) {
var files = evt.target.files;
localStorage["fname"] = files[0].name; //save the name for future use
}
$('.fileImage').bind('change', handleFileSelect, false);
var result = '';
if (success == 1){
result = '<span class="msg">The file ('+localStorage["fname"]+') was uploaded successfully!</span><br/><br/>';
localStorage["fname"] = undefined; //remove the temporary variable
}
else {
result = '<span class="emsg">There was an error during file upload!</span><br/><br/>';
}
return true;
}
양식입니다 :
<form action='imageupload.php' method='post' enctype='multipart/form-data' target='upload_target' onsubmit='stopImageUpload(this);' class='imageuploadform' >
<p>Image File: <input name='fileImage' type='file' class='fileImage' />
<input type='submit' name='submitImageBtn' class='sbtnimage' value='Upload' />
</p>
</form>
아, 'localStorage' 이전에 좋았어! –
@JimSchubert이 상황에서 왜 'localStorage'를 선호합니까? –
@KevinVanRyckegem 원래의 질문에서 localStorage를 사용하는 것에 대해이 더 바람직한 해결책을 비교 한 농담을했습니다. localStorage는 너무 큰 해머입니다. –