2015-09-06 52 views
0

我正在使用wordpress文件,並且在顯示總下載次數方面遇到問題。無法用php顯示輸出回顯

「下載計數」是我保存在活動主題文件中服務器上的文本文件「count.txt」中的一個數字。

現在爲了顯示計數,我使用下面的代碼。

<?php 
$url= echo get_the_title(); 

echo file_get_contents("http://example.com/wp-content/themes/themename/download/$url/count.txt"); 
//the URL of the text file consist of current wordpress post title. 
?> 

此代碼無法顯示count.txt。請幫我出

+0

這將失敗'$ URL =回聲get_the_title ();'一件事。回聲不合適,應該返回一個解析錯誤。只是刪除回聲 –

+0

這沒有工作,是任何其他方法嗎? count.txt的URL是>> http://example.com/wp-content/themes/themename/download/title當前文章/ count.txt –

+0

該文件是否實際存在於服務器上並且可以通過運行代碼的用戶(php/apache)?此外,權限檢查目​​錄'/下載' – ScottMcGready

回答

1

你應該先刪除從$url設置echo,然後用rawurlencode()使用file_get_contents()時,以確保URL正確編碼:

$url = get_the_title(); 

echo file_get_contents('http://example.com/wp-content/themes/themename/download/'.rawurlencode($url).'/count.txt'); 
+0

謝謝你的答案,但仍然無法顯示文本文件中的數量。該文本文件的URL是>> http://eragenx.com/wp-content/themes/Tesseract/download/Freelancer%20portfolio%20theme/count.txt <<如何顯示它與file_get_contents,因爲你可以看到該網址是可訪問的 –

+0

似乎這個網站需要'rawurlencode()'而不是'urlencode()'。我相應地編輯了我的答案。 – uri2x

+0

rawurlencode()工作。非常感謝 –