<input type="file" id="file-id" name="file_name" onchange="theimage();">
제 업로드 버튼입니다.
<input type="text" name="file_path" id="file-path">
파일의 전체 경로를 표시해야 하는 텍스트 필드입니다.
function theimage(){
var filename = document.getElementById('file-id').value;
document.getElementById('file-path').value = filename;
alert(filename);
}
이것이 제 문제를 해결한 자바스크립트입니다. 그러나 경고 값에서 다음과 같이 표시됩니다.
C:\fakepath\test.csv
를 제공하고 모질라에서는
C:\fakepath\test.csv
를 제공합니다:
test.csv
하지만 로컬 완전히 정규화된 파일 경로를 원합니다. 이 문제를 해결하려면 어떻게 해야 하나요?
브라우저 보안 문제로 인한 문제라면 다른 방법은 무엇인가요?
사용
document.getElementById("file-id").files[0].name;
대신
document.getElementById('file-id').value
내가 사용하는 사용자의 입력 파일 형식 '에 론창레 필레이더 객체에는 입력입니다' 이벤트! 이 예제는 리다다토를 기능, 이러한 이유로, img> < 있어야 합니다. 태그이고, 또한 이 필레이더 객체에는 리다비나리스트링 만드는 데 사용될 수 있는 이진 데이터를 얻기 위해 나중에 같은 파일 서버의
예:
var input = document.getElementById("inputFile");
var fReader = new FileReader();
fReader.readAsDataURL(input.files[0]);
fReader.onloadend = function(event){
var img = document.getElementById("yourImgTag");
img.src = event.target.result;
}
브라우저 해 주는 등 저희를 구하여 스크립트에만 돼 기쁘다. I am not look like a 만족하고 있다 할 수 있는 간단한 스타일 수리입니다. 뭔가 ie 를 브라우저 해킹 공격!
어쨌든, 그 덕분에 게시한 설명이 있습니다. IE 브라우저 보안: 추가 " fakepath"; 파일 경로를 입력 [유형 = ", file".], I& # 39, ve 동일팔레트에 함께 경미함 해결사 어퍼.
아래 코드는 버그 수정 론창레 이벤트를 doesn& 있는 lte IE8 이 두 가지를 않습니다 - # 39, t, s onBlur 때까지 불지옥의 field& 업로드하십시오 # 39 로 업데이트 파일 경로 및 정보기술 (it), t 사용자가 있는 요소를 클리닝했습니다. # 39 won& 배치되었다.
// self-calling lambda to for jQuery shorthand "$" namespace
(function($){
// document onReady wrapper
$().ready(function(){
// check for the nefarious IE
if($.browser.msie) {
// capture the file input fields
var fileInput = $('input[type="file"]');
// add presentational <span> tags "underneath" all file input fields for styling
fileInput.after(
$(document.createElement('span')).addClass('file-underlay')
);
// bind onClick to get the file-path and update the style <div>
fileInput.click(function(){
// need to capture $(this) because setTimeout() is on the
// Window keyword 'this' changes context in it
var fileContext = $(this);
// capture the timer as well as set setTimeout()
// we use setTimeout() because IE pauses timers when a file dialog opens
// in this manner we give ourselves a "pseudo-onChange" handler
var ieBugTimeout = setTimeout(function(){
// set vars
var filePath = fileContext.val(),
fileUnderlay = fileContext.siblings('.file-underlay');
// check for IE's lovely security speil
if(filePath.match(/fakepath/)) {
// update the file-path text using case-insensitive regex
filePath = filePath.replace(/C:\\fakepath\\/i, '');
}
// update the text in the file-underlay <span>
fileUnderlay.text(filePath);
// clear the timer var
clearTimeout(ieBugTimeout);
}, 10);
});
}
});
})(jQuery);
전체 경로를 찾을 수 없는 것 같다, 너회가 can& # 39 에서 볼 수 있지만 그냥 파크파스 숨김니다 로컬호스트 js 파일 이름. # 6365883 https://stackoverflow.com/questions/6365858/use-jquery-to-get-the-file-inputs-selected-filename-without-the-path/6365883
Hy (asp.net) 을 사용하고 있는데, 내 경우에는 이러한 data-in 라인크로노스 ajax 요청을 스맥랜드의 업로드입니다 개발 환경, 저는 " [웹메트로트] 에서 파일 있지 않기 때문에, 정적 요소점 업로더 잡을 수 없습니다. 그래서 이러한 문제를 해결하기 위해 할 수 있는 솔루션을 출시해 보다 인계합니다 경로를 변환하십시오 그들이성년에 로 이미지 바이트입니다 저장할 때 DB 에서.
이것은 자바스크립트 함수를, 내 희망이 있습니다.
function FixPath(Path)
{
var HiddenPath = Path.toString();
alert(HiddenPath.indexOf("FakePath"));
if (HiddenPath.indexOf("FakePath") > 1)
{
var UnwantedLength = HiddenPath.indexOf("FakePath") + 7;
MainStringLength = HiddenPath.length - UnwantedLength;
var thisArray =[];
var i = 0;
var FinalString= "";
while (i < MainStringLength)
{
thisArray[i] = HiddenPath[UnwantedLength + i + 1];
i++;
}
var j = 0;
while (j < MainStringLength-1)
{
if (thisArray[j] != ",")
{
FinalString += thisArray[j];
}
j++;
}
FinalString = "~" + FinalString;
alert(FinalString);
return FinalString;
}
else
{
return HiddenPath;
}
}
여기 대해서만 테스트:
$(document).ready(function () {
FixPath("hakounaMatata:/7ekmaTa3mahaLaziz/FakePath/EnsaLmadiLiYghiz");
});
// this will give you : ~/EnsaLmadiLiYghiz
파일을 사용하는 판독기에서:
$(document).ready(function() {
$("#input-file").change(function() {
var length = this.files.length;
if (!length) {
return false;
}
useImage(this);
});
});
// Creating the function
function useImage(img) {
var file = img.files[0];
var imagefile = file.type;
var match = ["image/jpeg", "image/png", "image/jpg"];
if (!((imagefile == match[0]) || (imagefile == match[1]) || (imagefile == match[2]))) {
alert("Invalid File Extension");
} else {
var reader = new FileReader();
reader.onload = imageIsLoaded;
reader.readAsDataURL(img.files[0]);
}
function imageIsLoaded(e) {
$('div.withBckImage').css({ 'background-image': "url(" + e.target.result + ")" });
}
}