服务器端未开启URL文件访问功能


URL file-access is disabled in the server

URL文件访问在服务器中被禁用-这是我使用短URL获得的错误。我不是PHP程序员,所以如果你能发布我应该使用的代码,我会很感激!如何重写路径?

在功能:

//////////////////////////////////////// Custom templates: page templates
add_filter('single_template', create_function('$t', 'foreach( (array) get_the_category() as $cat ) { if ( file_exists(TEMPLATEPATH . "/single-{$cat->term_id}.php") ) return TEMPLATEPATH . "/single-{$cat->term_id}.php"; } return $t;' ));

调用:

<?php $turl = getTinyUrl(get_permalink($post->ID));
echo 'Short URL <a href="'.$turl.'">'.$turl.'</a>' ?>

如果PHP启用了cURL,可以添加以下功能:

function getTinyUrl2($url) {
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_HEADER, 0);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Set curl to return the data instead of printing it to the browser.
  curl_setopt($ch, CURLOPT_URL, "http://tinyurl.com/api-create.php?url=".$url);
  $data = curl_exec($ch);
  curl_close($ch);
  return $data;
}

,然后更改代码以使用新函数:

$turl = getTinyUrl2(get_permalink($post->ID));
echo 'Tiny Url for this post: <a href="'.$turl.'">'.$turl.'</a>'

希望有帮助

Tinyurl.com不允许您通过php的file_get_contents函数获取文件。使用curl代替tinyurl api。

<?php
   $url = "http://example.com";
   $ch = curl_init("http://tinyurl.com/api-create.php?url=".$url);
   curl_setopt($ch, CURLOPT_RETURNTRANSFERT, true);
   $tinyurl = curl_exec($ch);
   curl_close($ch);
?>