2022年1月12日 星期三

檔案上傳預覽

 通常在html中要上傳檔案只要將input type 設定成file就可以了

<input type="file" name="Attach" id="Attach" />

但是............如圖


只會出現檔名,有可能我選擇完就忘了.自己選了什麼相片(相信我.年紀到了就會這樣..)

加上兩段code 就可以解決這個問題了

紅色部份是相片預覽的部份,橘色部份是上傳的部份


<div class="form-group row">

       <div class="col-md-8">

         <img id="ShowPrePic" src="#" alt="your image" style="max-width:300px;max-height:300px;" />

       </div>

        <div class="col-md-4">

            <input type="file" name="Attach" id="AJpic" />

        </div>

  </div>


<script >

AJpic.onchange = evt => {

            const [file] = AJpic.files

            if (file) {

                ShowPrePic.src = URL.createObjectURL(file)

            }

        }

</script>

 





沒有留言:

張貼留言

簽署時發生錯誤: 無法簽署 bin\Debug\app.publish\XXX.exe。SignTool Error: No certificates were found that met all the given criteria.

 這是一個程式碼簽署憑證的問題。當您的專案設定要進行程式碼簽署,但系統找不到合適的憑證時就會出現這個錯誤。以下是幾種解決方法: 方法 1:移除程式碼簽署設定 如果您不需要程式碼簽署,可以在專案中移除相關設定: 在 Visual Studio 中右鍵點擊專案 → 屬性 點擊「...