2015-09-06 126 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()工作。非常感谢 –