文件获取内容在localhost上有效,但在服务器上不起作用

时间:2018-10-31 14:23:06

标签: php wordpress

我对从url获取开放图元的函数有疑问:

 function post_updated_set_og_description( $post_id ) {

    $url = get_field('link', $post_id);
    $page_content = file_get_contents($url);

    $dom_obj = new DOMDocument();
    @$dom_obj->loadHTML($page_content);
    $meta_val = null;

    foreach($dom_obj->getElementsByTagName('meta') as $meta) {

      if($meta->getAttribute('property')=='og:description'){ 

      $meta_val = $meta->getAttribute('content');
    }

    update_post_meta($post_id, 'og_desc', $meta_val);

}}
add_action( 'save_post', 'post_updated_set_og_description' );

它在localhost上运行,但是当我在服务器上移动网站时,它不起作用。我有这样的错误:

  

警告:file_get_contents($ url):无法打开流:HTTP请求   失败了!禁止使用HTTP / 1.1 403 ...

我不知道如何解决

0 个答案:

没有答案