Ver Mensaje Individual
  #1 (permalink)  
Antiguo 07/08/2013, 18:53
haganex
 
Fecha de Ingreso: diciembre-2012
Mensajes: 9
Antigüedad: 11 años, 11 meses
Puntos: 0
subir archivos a google drive

chicos tengo un problema estoy utilizando la api de google drive para almacenar archivos y estoy intentando implementarlo pero al subir el archivo me da el siguiente error
Código:
Notice: Use of undefined constant STDIN - assumed 'STDIN' in C:\xampp\htdocs\google\subir.php on line 25

Warning: fgets() expects parameter 1 to be resource, string given in C:\xampp\htdocs\google\subir.php on line 25

Notice: Undefined variable: _File in C:\xampp\htdocs\google\subir.php on line 37

Warning: file_get_contents($arch): failed to open stream: No such file or directory in C:\xampp\htdocs\google\subir.php on line 38
Array ( [kind] => drive#file [id] => 0BzFaOweE3GfzTGY2SEF3LUpFdnM [etag] => "Q5ElJByAJoL0etObruYVPRipH1k/MTM3NTkyMjgyMjI3OQ" [selfLink] => https://www.googleapis.com/drive/v2/files/0BzFaOweE3GfzTGY2SEF3LUpFdnM [webContentLink] => https://docs.google.com/a/itlinesoftware.com/uc?id=0BzFaOweE3GfzTGY2SEF3LUpFdnM&export=download [alternateLink] => https://docs.google.com/a/itlinesoftware.com/file/d/0BzFaOweE3GfzTGY2SEF3LUpFdnM/edit?usp=drivesdk [iconLink] => https://ssl.gstatic.com/docs/doclist/images/icon_10_text_list.png [title] => codigos.txt [mimeType] => text/plain [description] => bonito [labels] => Array ( [starred] => [hidden] => [trashed] => [restricted] => [viewed] => 1 ) [createdDate] => 2013-08-08T00:47:01.491Z [modifiedDate] => 2013-08-08T00:47:02.279Z [modifiedByMeDate] => 2013-08-08T00:47:02.279Z [lastViewedByMeDate] => 2013-08-08T00:47:01.413Z [parents] => Array ( [0] => Array ( [kind] => drive#parentReference [id] => 0ADFaOweE3GfzUk9PVA [selfLink] => https://www.googleapis.com/drive/v2/files/0BzFaOweE3GfzTGY2SEF3LUpFdnM/parents/0ADFaOweE3GfzUk9PVA [parentLink] => https://www.googleapis.com/drive/v2/files/0ADFaOweE3GfzUk9PVA [isRoot] => 1 ) ) [downloadUrl] => https://doc-0g-00-docs.googleusercontent.com/docs/securesc/208qu0olu0tl4lfkhopsubo1na0g4uh5/8ukm2aget8nhgbpns6dijsvk63lkff72/1375920000000/08879570490478112418/08879570490478112418/0BzFaOweE3GfzTGY2SEF3LUpFdnM?h=09658256768764709298&e=download&gd=true [userPermission] => Array ( [kind] => drive#permission [etag] => "Q5ElJByAJoL0etObruYVPRipH1k/en4G14zFfi71dNmaWJDon5KKL34" [id] => me [selfLink] => https://www.googleapis.com/drive/v2/files/0BzFaOweE3GfzTGY2SEF3LUpFdnM/permissions/me [role] => owner [type] => user ) [originalFilename] => codigos.txt [fileExtension] => txt [md5Checksum] => d41d8cd98f00b204e9800998ecf8427e [fileSize] => 0 [quotaBytesUsed] => 0 [ownerNames] => Array ( [0] => Roberto Rivera ) [owners] => Array ( [0] => Array ( [kind] => drive#user [displayName] => Roberto Rivera [isAuthenticatedUser] => 1 [permissionId] => 08879570490478112418 ) ) [lastModifyingUserName] => Roberto Rivera [lastModifyingUser] => Array ( [kind] => drive#user [displayName] => Roberto Rivera [isAuthenticatedUser] => 1 [permissionId] => 08879570490478112418 ) [editable] => 1 [copyable] => 1 [writersCanShare] => 1 [shared] => [appDataContents] => )
y el form donde recibo el archivo
Código HTML:
<form method="post" action="subir.php" enctype="multipart/form-data">
	codigo de validacion <input type="text" name="codigo"/><button><a href="codigo.php" target="_blank">generar codigo</a></button></br>
	nombre del archivo <input type="text" name="nombreArchivo"/></br>
	Seleccione el archivo:<input type="file" name="documento"><br>
	<input type="submit" value="ok"/>
</form> 
con este es donde tengo problemas estoy aprendiendo hace poco php orientado a objetos
Código PHP:
<?php
require_once 'google-api-php-client/src/Google_Client.php';
require_once 
'google-api-php-client/src/contrib/Google_DriveService.php';

$client = new Google_Client();
// Get your credentials from the APIs Console
$client->setClientId('');
$client->setClientSecret('');
$client->setRedirectUri('urn:ietf:wg:oauth:2.0:oob');
$client->setScopes(array('https://www.googleapis.com/auth/drive'));

$service = new Google_DriveService($client);

$authUrl $client->createAuthUrl();

//Request authorization
//recuperacion de datos
$codigo $_POST['codigo'];
$nombre $_FILES['documento']['name'];
$arch $_File['documento']['tmp_name'];
$x "bonito";


//fin
$authCode trim(fgets(STDIN));
$authCode "$codigo";
// Exchange authorization code for access token
$accessToken $client->authenticate($authCode);
$client->setAccessToken($accessToken);

//Insert a file
$file = new Google_DriveFile();
$file->setTitle("$nombre");
$file->setDescription("$x");
$file->setMimeType('text/plain');

$data file_get_contents('$arch');

$createdFile $service->files->insert($file, array(
      
'data' => $data,
      
'mimeType' => 'text/plain',
    ));

print_r($createdFile);
?>
con este obtengo el codigo de validacion entregado por google
Código PHP:
<?php

    
require_once 'google-api-php-client/src/Google_Client.php';
    require_once 
'google-api-php-client/src/contrib/Google_DriveService.php';

    
$client = new Google_Client();
    
// Get your credentials from the APIs Console
    
$client->setClientId('');
    
$client->setClientSecret('');
    
$client->setRedirectUri('urn:ietf:wg:oauth:2.0:oob');
    
$client->setScopes(array('https://www.googleapis.com/auth/drive'));

    
$service = new Google_DriveService($client);

    
$authUrl $client->createAuthUrl();

    
//Request authorization

    
$authCode trim(fgets(STDIN));
    
// Exchange authorization code for access token
    
$accessToken $client->authenticate($authCode);
    
$client->setAccessToken($accessToken);

?>

gracias por la ayuda