Wordpress Random Quote:读取远程文件错误

Filed at 9:34 pm under 有趣的东西 and 电脑 by biantaishabi

今天弄了几个WordPress的插件, 其中有一个random quote, 我想在左边栏随机的显示quote, 就像在27th上面看到的那样, 但是自己又懒得去手动添加那些quotes, 所以找了一个可以读取外部的quotes的插件。 但是出现了类似这样的错误提示, Warning: fopen(http://somelocation.com/somefile.xml) [function.fopen]: failed to open stream: no suitable wrapper could be found in /home/someuser/somephpfile.php on line [someline]

我也没有用过php, 于是google了一下,发现是因为我的这个虚拟主机为了安全的考虑, 禁止了fopen打开远程文件。 但是也找到了解决的方法

那就是将插件中的打开文件的代码, 例如

 

$file = “http://somelocation.com/somefile.xml”;
$fp = fopen($file, “r”);

替换为

 

$file = “http://somelocation.com/somefile.xml”;
$ch = curl_init($file);
$fp = @fopen(”temp.xml”, “w”);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
$file = “temp.xml”;
$fp = fopen($file, “r”);

其中$fp, $file与插件程序中的变量名保持一致就可以了。 似乎使用一个叫curl的东西, 将文件写到本地的临时文件中再用fopen打开, 就解决了这个fopen不能打开远程文件的限制。 可以将quotes显示在左边。 不过都是英文的。 但是发现打开这个quotes突然变得很慢, 就暂时把他去掉了。

除了这个random quote还加了最近的留言和帖子的显示的插件。 还在主机上装了留言本FAQ生成器PmWikiJoomla。 其实好像并没有什么用, 只是服务商提供了这些东西的一键安装,就把他们装上去玩玩。

这个故事告诉我们,人们在玩新东西的时候总是充满了热情,比如新买了一个虚拟主机空间之后。

7 Responses to “Wordpress Random Quote:读取远程文件错误”


Comment by
cathayan
September 9th, 2006
at 9:44 pm

这个故事告诉我们,你的Blog改了之后变得好慢啊,不知道是不是你这个什么插件的功劳


Comment by
biantaishabi
September 9th, 2006
at 9:47 pm

确实是这个插件的原因
白天还是好的
晚上突然就不行了
好像是因为他那个host的原因
所以把他去掉了


Comment by
biantaishabi
September 9th, 2006
at 9:50 pm

白搞了半天, 呵呵


Comment by
flying_water
September 9th, 2006
at 10:22 pm

买了新东西的确会有玩的热情,今天我就买了Palm的Treo 650来替代掉了我的旧手机,Hoho


Comment by
magoi-> (PL)
September 10th, 2006
at 12:02 pm

试一下


Comment by
magoi->
September 10th, 2006
at 12:02 pm

再试一下


Comment by
传奇外传吧
November 28th, 2008
at 6:48 pm

^_^欢迎访问我的小站。传奇外传吧的小站

Leave a Reply