簡體   English   中英

如何使用 html、javascript、php 獲取上傳的文件路徑

[英]how to get the uploaded file path using html , javascript , php

我正在從我的驅動器上傳圖像,它已成功上傳,但我無法獲取該圖像的文件夾路徑

例如:

E:\Allied 標志\Allied 標志圖片

$('#pngfile').change(function (e) {
var tmppath = URL.createObjectURL(e.target.files[0]);
console.log(this.files,tmppath);
        })

它會給你一個臨時路徑而不是准確的路徑,如果你想顯示選定的圖像,你可以使用這個腳本。

這是代碼: -

HTML:-

<input type="file" id="i_file" value=""> 
<input type="button" id="i_submit" value="Submit">
<br>
<img src="" width="200" style="display:none;" />
<br>
<div id="disp_tmp_path"></div>

JS: -

    <script type="text/javascript">
    $('#i_file').change( function(event) {
        var tmppath = URL.createObjectURL(event.target.files[0]);
        $("img").fadeIn("fast").attr('src',URL.createObjectURL(event.target.files[0]));
    
        $("#disp_tmp_path").html("Temporary Path(Copy it and try pasting it in browser address bar) --> <strong>["+tmppath+"]</strong>");
    });
   </script>

Jquery

<script type="text/javascript"> 
  $(function(){
    
            $('#fiad').change( function(event) {
                                                    var tmppath = URL.createObjectURL(event.target.files[0]);
                                                    $("img").fadeIn("fast").attr('src',tmppath);
                
            });
  });  
  </script>

Html

<input type="file" id="fiad"><br><br>

<img src="" width="200" style="display:none;" />

您在此處獲得tmppath內的文件路徑。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM