2013-05-11 320 views
1

我試圖使用定位標記訪問上傳的圖像,該圖像已保存在我的服務器上(位於上傳文件夾中)。目標是提供像縮放功能。縮放工作正常,但圖像不顯示。 我想是這樣的
將php代碼添加到html定位標記

<?php 
//$txt is the actual image name and $image is the name saved in uploads folder,$ext is the extension like .jpg or so. 
$image = time().substr(str_replace(" ", "_", $txt), 5).".".$ext; 
?> 

在HTML

//image isn't displayed using 
<a href = "<?php echo "uploads/$image" ?>"></a> 

但顯示如果我使用

<a href = "uploads/image.jpg"></a>. 

是有辦法,我可以用PHP代碼中訪問的圖像標籤?

回答

2

你錯過了一個分號,$變量被括在單引號中,因此沒有展開。

<a href="uploads/<?php echo $image; ?>">Image</a> 

安東尼。

+0

現在工作正常..謝謝 – dhani 2013-05-11 21:41:49

+0

嗨,我還有一個問題。我的腳本中有一些html代碼,我通過echo執行。假設我想從該回聲中訪問uploads文件夾中的圖像,我該怎麼做?我試過這個; 'echo'

2

您未關閉<?PHP標記。像

<a href = "<?php echo 'uploads/$image'; ?>"></a> 
+0

對不起,在輸入問題時出錯。我編輯過它。 我實際上在我的代碼中正確關閉它 – dhani 2013-05-11 21:18:42

+0

@dhani:現在關閉標記存在,但沒有用echo指定的變量。你能否發佈你正在使用的確切代碼? – mithunsatheesh 2013-05-11 21:21:52

+0

你需要'echo「uploads/$ image」;' – Orangepill 2013-05-11 21:21:54