2012-09-19 20 views
1

我似乎無法從桌面上獲取我的圖像,並將其放入我的一個div標籤中。有人可以幫幫我嗎。如何從桌面讀取圖像並輸入到​​div標籤中?

<!DOCTYPE html> 
<html> 
    <body> 
    <img src="C:\Users\aldiaz\Desktop\DynamicsTest1.jpg"> 
     <div id="container" style="width:500px"> 
      <div id="header" style="background-color:#0000F8;"> 
       <h1 style="margin-bottom:0;"> Triton Subs</h1> 
      </div> 
      <div id="image" style="background-color:yellow; height:200px;width:100px;float:left;"> 
       <img src="C:\Users\aldiaz\Desktop\DynamicsTest1.jpg height:200px; width:100px;floatleft;"> 
      </div> 
      <div id="content" style="background- color:#D7D7D7;height:200px;width:400px;float:left;">Dear [FIRSTNAME] [LASTNAME],<br/> <br/>You have earned 5 videos and are ready to redeem.<br/><br/>Log into the Triton Submarines Experience now to choose your reward! 
      </div> 
      <div id="footer" style="background-color:#0000F8;clear:both;text-align:center;"> Trinto Sub Co 
      </div> 
     </div> 
    </body> 
</html> 
+2

使用相對路徑。另外注意第二個img標籤的src。如果上傳到服務器上,您的代碼將無法使用。所以最好在根目錄下創建一個文件夾'images'並使用相對路徑。 – Dev

+0

可能您的Web服務器沒有對用戶桌面文件夾的讀取訪問權限...... – jtheman

+1

@Yusuf - 在回答問題後,您不應該刪除問題。其他人也可能從看到問題及其答案中受益。 –

回答

3

你需要寫:

<img src="C:\Users\aldiaz\Desktop\DynamicsTest1.jpg" style="height:200px;width:100px;float:left"> 
1

如果HTML文件是您的桌面上,然後用一個相對文件路徑,如:

<img src="images/DynamicsTest1.jpg"> 
1

不支持瀏覽器讓你像訪問你的計算機上的文件(嗯,IE確實,但它不應該)。這被認爲是一個安全漏洞。即使允許,也沒有其他人訪問該頁面將能夠看到圖像,因爲他們的計算機上可能沒有一個名爲aldiaz的用戶,即使他們這樣做了,該圖像可能不會存在於他的他的桌面。

如果您在上傳到網絡服務器之前進行測試時在本地鏈接圖像,請使用相對URL,而不是像其他人所建議的那樣。

現在,如果你正在尋找一個用戶上傳之前預覽圖像,還有許多精美的教程有關於如何使用較新的FileReader API:

http://html5doctor.com/drag-and-drop-to-server/

相關問題