2017-05-26 5 views
2

Meine Codes erreicht ist:file_get_contents, failed to open stream: Umleitungs Limit

if (isset($_POST['gd_url']) && isset($_POST['accessToken'])) { 
    $url = "https://drive.google.com/uc?export=download&id=".$fileId; 
    // $url = $_POST['gd_url']; 
    $name = $_POST['file']; 
    $accessToken = $_POST['accessToken']; 
    $opts = array(

      'http'=>array(
      'method'=>"GET", 
      'header' => "Authorization: Bearer " . $accessToken     
      ) 
    ); 
    $context = stream_context_create($opts); 

    $content = file_get_contents($url, false, $context); 
    // echo $content; 
    if (!empty($content)){ 

     file_put_contents($_SERVER['DOCUMENT_ROOT'].'/UPDRIVE/'.$name,$content); 
    } 
} 

ich versuche hinzufügen 'follow_location' => false und 'max_redirects' => 101 aber das gleiche Ergebnis

Fehler:

Warning: file_get_contents(https://drive.google.com/uc?export=download&id=0B6ijT2xI7CfebEt3d3g1dndtZlU): failed to open stream: Redirection limit reached, aborting in /.../uploadMediasSupdrive.php on line 24 

wenn Ich ändere die Ligne

$content = file_get_contents($url, false, $context); 

zu

$content = file_get_contents($url); 

diese Arbeit nur mit * .jpg Datei

Danke

Antwort

0
$param = $_REQUEST; 
$oAuthToken = $param['oAuthToken']; 
$fileId = $param['fileId']; 
$getUrl = 'https://www.googleapis.com/drive/v2/files/' . $fileId . '?alt=media'; 
$authHeader = 'Authorization: Bearer ' . $oAuthToken; 
ini_set('memory_limit', '512M'); 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_URL, $getUrl); 
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    $authHeader 
)); 

curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
$data = curl_exec($ch); 
$error = curl_error($ch); 
curl_close($ch); 

file_put_contents($param['name'], $data); 

das ist die Lösung, die ich gefunden

0

ich eine Lösung für das Problem "failed to open stream: Umleitungsgrenze erreicht" gefunden

durch Hinzufügen dieser Linie: 'ignore_errors' => true,

$opts = array(
      'http'=>array(
      'method'=>"GET", 
      'ignore_errors' => true, 
      'header' => "Authorization: Bearer " . $accessToken 
      ) 
    ); 

, aber ich habe ein anderes Problem, wenn ich das Skript ich diese Nachricht bekam ausführen:

MOVED TEMPORARILY 
The document has moved here. 

oder

Google Drive ne peut pas effectuer l'analyse antivirus de ce fichier 

können Sie mir helfen

Verwandte Themen