2011-02-07 48 views
1

我有,當我嘗試上傳文件到Amazon S3這個問題,它給了我這個錯誤,但我天璣似乎明白了:CURLOPT_FOLLOWLOCATION出錯了嗎?

Warning: curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when safe_mode is enabled or an open_basedir is set in /var/www/vhosts/??????/httpdocs/actions/S3.php on line 1257 
+0

我殘疾的safe_mode但IM仍然得到錯誤,即時通訊使用1and1 :))謝謝 – pingpong 2011-02-07 19:00:13

回答

0

的問題是究竟什麼是錯誤消息說 - 你有在php.ini中啓用safe_mode或open_basedir。您可以編輯php.ini來禁用其中的任何一個,也可以不使用PHP的捲曲風格。如果你不能編輯php.ini,你必須找到一個新的主機或找到一個新的解決方案。

+0

嘿我disbaled safe_mode和open_ba sedir關閉,但它直到不工作,並給我相同的錯誤 – pingpong 2011-02-07 22:23:45

0

最好的解決方案是獲得一個新的主機。 open_basedir不是一個很好的安全功能(一個好的主持人會使用更好的方法建立一個監獄)。 safe_mode已棄用。所以最好的結果將來自於禁用這兩個指令(或者如果你不願意的話找到一個新的主機)。

但是,如果這不是一個選項,你可以隨時實現類似this(從php.net評論)...

0

我有解決辦法發表馬里奧短,安全性較差的變體,但你會發現它與重定向的已知數量的網址有用(例如FB圖形API調用圖像 - graph.facebook.com/4/picture)

function cURLRequest($url) { 
    $ch = curl_init(); 
    // curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
    curl_setopt($ch, CURLOPT_HEADER, 0); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
    curl_setopt($ch, CURLOPT_URL, $url); 
    $result = curl_exec($ch); 

    if ($result) { 
     curl_close($ch); 
     return $result; 
    } else if (empty($result)) { 
     $info = curl_getinfo($ch); 
     curl_close($ch); 
     // PHP safe mode fallback for 302 redirect 
     if (!empty($info['http_code']) && !empty($info['redirect_url'])) { 
      return cURLRequest($info['redirect_url']); 
     } else { 
      return null; 
     } 
    } else { 
     return null; 
    } 
} 
0

使用此版本捲毛

//=================== compressed version===============(https://github.com/tazotodua/useful-php-scripts/) 
function get_remote_data($url, $post_paramtrs=false) { $c = curl_init();curl_setopt($c, CURLOPT_URL, $url);curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); if($post_paramtrs){curl_setopt($c, CURLOPT_POST,TRUE); curl_setopt($c, CURLOPT_POSTFIELDS, "var1=bla&".$post_paramtrs);} curl_setopt($c, CURLOPT_SSL_VERIFYHOST,false);curl_setopt($c, CURLOPT_SSL_VERIFYPEER,false);curl_setopt($c, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; rv:33.0) Gecko/20100101 Firefox/33.0"); curl_setopt($c, CURLOPT_COOKIE, 'CookieName1=Value;'); curl_setopt($c, CURLOPT_MAXREDIRS, 10); $follow_allowed= (ini_get('open_basedir') || ini_get('safe_mode')) ? false:true; if ($follow_allowed){curl_setopt($c, CURLOPT_FOLLOWLOCATION, 1);}curl_setopt($c, CURLOPT_CONNECTTIMEOUT, 9);curl_setopt($c, CURLOPT_REFERER, $url);curl_setopt($c, CURLOPT_TIMEOUT, 60);curl_setopt($c, CURLOPT_AUTOREFERER, true);   curl_setopt($c, CURLOPT_ENCODING, 'gzip,deflate');$data=curl_exec($c);$status=curl_getinfo($c);curl_close($c);preg_match('/(http(|s)):\/\/(.*?)\/(.*\/|)/si', $status['url'],$link);$data=preg_replace('/(src|href|action)=(\'|\")((?!(http|https|javascript:|\/\/|\/)).*?)(\'|\")/si','$1=$2'.$link[0].'$3$4$5', $data);$data=preg_replace('/(src|href|action)=(\'|\")((?!(http|https|javascript:|\/\/)).*?)(\'|\")/si','$1=$2'.$link[1].'://'.$link[3].'$3$4$5', $data);if($status['http_code']==200) {return $data;} elseif($status['http_code']==301 || $status['http_code']==302) { if (!$follow_allowed){if(empty($redirURL)){if(!empty($status['redirect_url'])){$redirURL=$status['redirect_url'];}} if(empty($redirURL)){preg_match('/(Location:|URI:)(.*?)(\r|\n)/si', $data, $m);if (!empty($m[2])){ $redirURL=$m[2]; } } if(empty($redirURL)){preg_match('/href\=\"(.*?)\"(.*?)here\<\/a\>/si',$data,$m); if (!empty($m[1])){ $redirURL=$m[1]; } } if(!empty($redirURL)){$t=debug_backtrace(); return call_user_func($t[0]["function"], trim($redirURL), $post_paramtrs);}}} return "ERRORCODE22 with $url!!<br/>Last status codes<b/>:".json_encode($status)."<br/><br/>Last data got<br/>:$data";}