Gallery:当url fopen禁用时如何使用外部图片区块

来自站长百科
Sunzz1985讨论 | 贡献2008年6月11日 (三) 09:22的版本 (新页面: Some webhosts disable PHP url_fopen for security purposes. That's not a bad idea. But then you'll have to use the following code snippet instead of readfile(). User '''personman''' from ...)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
跳转至: 导航、​ 搜索

Some webhosts disable PHP url_fopen for security purposes. That's not a bad idea. But then you'll have to use the following code snippet instead of readfile().

User personman from the forums wrote this small code snippet. Requirement is libcurl. So it might or might not work on your webserver, depending on this requirement.

<?php
$ch = curl_init();
$timeout = 5; // set to zero for no timeout
curl_setopt ($ch, CURLOPT_URL, 'http://www.example.com/gallery/main.php?g2_view=imageblock.External&g2_blocks=randomImage&g2_show=title');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
curl_close($ch);
echo $file_contents;
?>

Replace

http://www.example.com/gallery/main.php?g2_view=imageblock.External&g2_blocks=randomImage&g2_show=title

with your own external image block URL which can be found in Site admin -> Image Block

See: http://gallery.menalto.com/node/36604#comment-133000