본문으로 바로가기
반응형

파일 용량에 대해 알아보다가 정리해서 작성해보려고 합니다.

input file 태그에서 첨부한 파일에 대한 정보를 확인해 보겠습니다.

<html>
	<head>
		<title>File Test</title>
		<script type='text/javascript'>
			//1MB(메가바이트)는 1024KB(킬로바이트)
			var maxSize = 2048;
			
			function fileCheck() {
				//input file 태그.
				var file = document.getElementById('fileInput');
				//파일 경로.
				var filePath = file.value;
				//전체경로를 \ 나눔.
				var filePathSplit = filePath.split('\\'); 
				//전체경로를 \로 나눈 길이.
				var filePathLength = filePathSplit.length;
				//마지막 경로를 .으로 나눔.
				var fileNameSplit = filePathSplit[filePathLength-1].split('.');
				//파일명 : .으로 나눈 앞부분
				var fileName = fileNameSplit[0];
				//파일 확장자 : .으로 나눈 뒷부분
				var fileExt = fileNameSplit[1];
				//파일 크기
				var fileSize = file.files[0].size;
				
				console.log('파일 경로 : ' + filePath);
				console.log('파일명 : ' + fileName);
				console.log('파일 확장자 : ' + fileExt);
				console.log('파일 크기 : ' + fileSize);
			}
		</script>
	</head>
	<body>
		<input type='file' id='fileInput'>
		<input type='button' value='확인' onclick='fileCheck()'>
	</body>
</html>

위에 파일 경로에서 왜 fakepath로 나오지 하고 찾아봤는데 신기했습니다.

관련된 내용은 찾아본 결과 JavaScript로 로컬 파일에 접근할 수 없게 되었다고 확인했습니다.

반응형