2014-07-10 360 views
-2

這可能有一個簡單的答案,但目前爲止我沒有找到運氣。包含圖像時損壞

我有兩個php頁面,index.php和headerBake.php。 headerBake.php包含在index.php中,除了兩個小圖像(一個twitter圖標和facebook圖標)被破壞之外,一切看起來都是應該的。圖像在headerBake.php中被引用和鏈接,並且圖標的文件路徑是正確的。

我的問題是:

我必須包括圖標分開,以讓他們露面包括?還是有什麼我失蹤?

我的問題與global paths有關嗎?

我的代碼 -

headerBake.php:

<link href="bakery.css" rel="stylesheet" type="text/css" /> 
    <header class="header" role="banner"> 
     <div id="innerHeader"> 
     <div id="logo"><a href="index.html">Auntie Jane's Bakery and Catering</a></div> 
     <div id="socialPhone"> 
      <div id="socialIcons"> 
      <a href="http://facebook.com"> 
       <img src="LogoSocial/social_facebook_box_blue.png" width="24px" /></a> 
      <a href="http://twitter.com"> 
       <img src="LogoSocial/Twitter-Icon.png" width="27px" /> 
      </a> 
      </div> 
      <div class="clear-div"></div> 
      <div id="bakeryNumber">Order online or Call: #860-538-8900</div> 
      <div class="clear-div"></div> 
     </div> 
     <div class="clear-div"></div> 
     </div> 
     <ul id="navBar"> 
     <li><a href="aboutUs.html">About Us</a></li> 
     <li><a href="Menu.html">Menu</a> 
      <ul> 
      <li><a href="weddingcakes">Wedding Cakes</a></li> 
      <li><a href="celebrationcakes">Celebration Cakes</a></li> 
      <li><a href="cupcakes">Cupcakes</a></li> 
      <li><a href="cookies">Cookies</a></li> 
      <li><a href="brownies">Brownies</a></li> 
      </ul> 
     </li> 
     <li><a href="catering.html">Catering</a></li> 
     <li><a href="contact.html">Contact Us</a></li> 
     </ul> 
    </header> 

的index.php

<body> 
     <div id="wrapper"> 
     <div id="indexContent"> 
      <div class="slideshow"></div> 
      <div class="clear-div"></div> 
      <div class="newscolumn"></div> 
      <div class="clear-div"></div> 
     </div> 
     </div> 

    <footer> 
     <div id="sitemap"> 
     <div id="menu"> 
      <p><h4>SiteMap:</h4> 
      <br /> 
      Menu:<br /> 
      Wedding Cakes | Celebration Cakes<br /> 
      Cupcakes | Cookies | Brownies<br /> 
      About Us | Catering | Contact Us 
      </p> 
     </div> 
     <div id="address"> 
      <p>We are located at:<br /> 
      123 Parker Lane<br /> 
      Hartford, CT 06103 
      </p> 
     </div> 
     <div class="clear-div"></div> 
     </div> 
    </footer> 
</body> 
    </html> 

編輯:我的所有文件,包括圖標圖像,現在所有人都在同一個地方:

http://imgur.com/uKvdVpo

驚喜,我仍然有斷鏈圖像鏈接。

+0

什麼是你的項目結構? – Onion

+0

學習如何使用'./'和'../'來形成合適的相對路徑。而且這應該只能被標記爲HTML。是的,你有PHP文件中的HTML,但是PHP根本不涉及這個問題。 – developerwjk

+1

這可能是包含與索引位置相關的問題。你可能最好給他們絕對路徑。 – Samsquanch

回答

0

後有固定的格式不正確的代碼,並驗證了圖像的直接訪問,在瀏覽器中一個403錯誤響應...

http://localhost/Bakery/logodesign1.png 

你得到Error 403(禁止) 所以問題必須依賴於服務器...

嘗試以下操作終端更改權限:(正如我在你的截圖中看到,你在OS & XAMPP)

cd /Applications/XAMPP/xamppfiles/htdocs/Bakery 
find . -type f -exec chmod 644 {} \; 
find . -type d -exec chmod 755 {} \; 

現在再試一次:

http://localhost/Bakery/logodesign1.png 

必須得到Error 200現在,這是很好的

0

假設你的圖像位於(mywebsite)/ LogoSocial /(圖標)。PNG,嘗試改變形象鏈接:

<img src="/LogoSocial/<icon>.png" ... > 

的斜線表示,「從根開始尋找這個對象你的網站的水平「。

0

它與你的php代碼無關。這都是關於絕對和相對路徑。

如果您的路徑以前導斜槓/開頭,則瀏覽器將嘗試從根目錄獲取資源。 如果它不以斜槓啓動,則該鏈接將被視爲相對路徑。

例如,假設您的index.php位於此處http://domain.com/blah/index.php

  • 鏈接LogoSocial/social_facebook_box_blue.png這是你目前的ressource(http://domain.com/blah/index.php)一 相對路徑將導致:

    http://domain.com/blah/LogoSocial/social_facebook_box_blue.png

  • 在另一方面,這絕對路徑 /LogoSocial/social_facebook_box_blue.png(注意引導斜槓) 將導致:

    http://domain.com/LogoSocial/social_facebook_box_blue.png

    對於這種情況下的根目錄是http://domain.com/

0

我猜你正試圖加載你的圖片相對於你的headerBake.php文件的位置。

當你使用PHP來包含文件時,試想一下,文件中的代碼被複制並粘貼到index.php中。

PHP是一種服務器端語言,在這種情況下,它負責生成一個HTML響應。一旦生成響應並返回給瀏覽器,瀏覽器就不知道使用了哪些PHP文件以及它們的位置。

您的圖片需要被瀏覽器訪問,例如: http://example.com/img/something.png。正如其他人所建議的那樣,我會使用絕對路徑而不是相對路徑。