2012-04-13 2 views
3

1つのサイトを別のWebホスティングに移動しました。私はローカルホストでテストすると、すべてが正常に動作しますが、私はそれをオンラインでしようとすると、私は次のように受け取る:私はTCPDFでPDFファイルを生成しようとすると、curl_setopt()TCPDFのCURLOPT_FOLLOWLOCATION問題

curl_setopt() [<a href='function.curl-setopt'>function.curl-setopt</a>]: 
    CURLOPT_FOLLOWLOCATION cannot be activated when safe_mode is enabled or 
    an open_basedir is set 

7534    if ($imsize === FALSE) { 
7535     if (function_exists('curl_init')) { 
7536      // try to get remote file data using cURL 
7537      $cs = curl_init(); // curl session 
7538      curl_setopt($cs, CURLOPT_URL, $file); 
7539      curl_setopt($cs, CURLOPT_BINARYTRANSFER, true); 
7540      curl_setopt($cs, CURLOPT_FAILONERROR, true); 
7541      curl_setopt($cs, CURLOPT_RETURNTRANSFER, true); 
7542      curl_setopt($cs, CURLOPT_FOLLOWLOCATION, true); 
を(ライン7542は、エラーを生成しています)

これを避けるにはどうすればよいですか?

+0

に変更する必要があり、それはPHPのセーフモードでいるようです。 – safarov

+0

私はチェックしています –

+0

あなたはphp.iniのopen_basedirをコメントアウトしてみることができますか? –

答えて

0

エラーメッセージが間違っているかを表示します:

CURLOPT_FOLLOWLOCATIONセーフモードが有効になっているかopen_basedirのが

  • safe_mode­Docs
  • open_basedir­Docs
    • に設定されている場合に活性化することができませんあなたはこのようにあなたの現在の設定を取得することができるはずです。

      var_dump(array_map('ini_get', array('safe_mode', 'open_basedir'))); 
      

      、エラーを取り除くあなたのホスティング事業者のサポート部門に話をし、PHPの設定のためのあなたの技術要件についてのそれらを伝えるために。ホスティング事業者が要件を満たすことができない場合、PHPスクリプトに間違ったホスティングプロバイダを選択したことになります。ホスティング会社/部署はセーフモードをオフにすることを望んでいない場合

    +0

    これはcurlをopen_basedir設定に追加する方法をユーザーに教えてくれません。 PHP 5.3以降 - safe_modeは自動的に無効になります。 – JM4

    +0

    @JMA:現在の安定版PHP 5.4では無効になっています。そして、open_basedirの設定AFAIKにカールを追加することはできません。 – hakre

    1

    回避策は、この便利なスニペットはあなたのホストにsafe_modeopen_basedirをオフにする必要がありphp.net http://php.net/manual/ro/function.curl-setopt.php#71313

    function curl_redir_exec($ch) 
    { 
        static $curl_loops = 0; 
        static $curl_max_loops = 20; 
        if ($curl_loops++ >= $curl_max_loops) { 
         $curl_loops = 0; 
         return FALSE; 
        } 
        curl_setopt_array($ch, array(CURLOPT_HEADER => true, CURLOPT_RETURNTRANSFER => true)); 
        $data = curl_exec($ch); 
        list($header, $data) = explode("\n\n", $data, 2); 
        $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); 
        if ($http_code == 301 || $http_code == 302) { 
         $matches = array(); 
         preg_match('/Location:(.*?)\n/', $header, $matches); 
         $url = @parse_url(trim(array_pop($matches))); 
         if (!$url) { //couldn't process the url to redirect to 
          $curl_loops = 0; 
          return $data; 
         } 
         $last_url = parse_url(curl_getinfo($ch, CURLINFO_EFFECTIVE_URL)); 
         foreach(array('scheme', 'host', 'path') as $component) { 
          if (!$url[$component]) { 
           $url[$component] = $last_url[$component]; 
          } 
         } 
         $new_url = $url['scheme'] . '://' . $url['host'] . $url['path'] 
           . ($url['query'] ? '?' . $url['query'] : ''); 
         curl_setopt($ch, CURLOPT_URL, $new_url); 
         return curl_redir_exec($ch); 
        } else { 
         $curl_loops = 0; 
         return $data; 
        } 
    } 
    
    +0

    恐ろしい回避策! –

    0

    で発見される可能性があります。あなたはホスティングサポートから尋ねることができます。使用できない場合は、open_basedirの値を(0)に変更できます。

    例:

    curl_setopt($rConnect, CURLOPT_RETURNTRANSFER, 1); 
        curl_setopt($rConnect, CURLOPT_FOLLOWLOCATION, 1); 
    

    curl_setopt($rConnect, CURLOPT_RETURNTRANSFER, 0); 
        curl_setopt($rConnect, CURLOPT_FOLLOWLOCATION, 0);