访问上传​​文件的URL

时间:2017-05-30 08:38:05

标签: javascript file url input

我想通过Javascript访问我从浏览器上传的文件的url。你能救我吗?



fileUpload = function () {
        var fileUpload = document.getElementById("fileUpload");
        

        guid = (S4() + S4() + "-" + S4() + "-4" + S4().substr(0, 3) + "-" + S4() + "-" + S4() + S4() + S4()).toLowerCase();
        console.log(guid);

       
    }

<div class="col-md-4 fileUpload btn btn-primary">
                <span>Dosya Yükle</span>
                <input type="file" class="upload" name="fileToUpload" id="fileUpload" onchange="fileUpload()" />
            </div>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

您可以使用

&#13;
&#13;
  document.querySelector('.upload').addEventListener('change',function(){
    var fileUrl = this.value,
				fileName = this.files[0].name;
        alert('Your url is '+ fileUrl )
        alert('Your file name is '+ fileName)
  });
&#13;
.file_upload {
	margin-bottom: 30px;
	position: relative;
	cursor: pointer;
	background: #73af27;
	display: inline-block;
	height: 40px;
	line-height: 40px;
	color: #fff;
	padding: 0 15px;
	text-align: center;
	-moz-transition: all 0.3s 0.03s ease;
	-o-transition: all 0.3s 0.03s ease;
	-webkit-transition: all 0.3s 0.03s ease;
	border: 0;
}
.file_upload [type="file"] {
	position: absolute;
	top: 0;
	right: 0;
	bottom: 0;
	left: 0;
	visibility: hidden;
	opacity: 0;
}
&#13;
<div class="file-upload">
  <label class="file_upload" data-error="This format is not correct">
    <span>Attach CV</span>
    <input type="file" name="file" class="upload" accept="aplication/pdf, aplication/doc, aplication/rtf, aplication/docx">
  </label>
</div>
&#13;
&#13;
&#13;