我在php中,我需要自动附加一个谷歌驱动器文件,通过邮件发送。 我现在拥有的是:
HTML表格如下:
TIPO
<span class="js-sorter-desc glyphicon glyphicon-chevron-up pull-right"></span>
<span class="js-sorter-asc glyphicon glyphicon-chevron-down pull-right"></span>
</th>
<th data-field="Etiquetas" data-align="left" data-sortable="true">Etiquetas
<span class="js-sorter-desc glyphicon glyphicon-chevron-up pull-right"></span>
<span class="js-sorter-asc glyphicon glyphicon-chevron-down pull-right"></span>
</th>
<th data-field="Fecha" data-align="left" data-sortable="true">Fecha
<span class="js-sorter-desc glyphicon glyphicon-chevron-up pull-right"></span>
<span class="js-sorter-asc glyphicon glyphicon-chevron-down pull-right"></span>
</th>
<th data-field="Nombre" data-align="left" data-sortable="true">Nombre
<span class="js-sorter-desc glyphicon glyphicon-chevron-up pull-right"></span>
<span class="js-sorter-asc glyphicon glyphicon-chevron-down pull-right"></span>
</th>
</tr>
<tr class="fila_filtros filtros_buscador_drive">
<th>
<input class="js-filter form-control" type="text" value="">
</th>
<th>
<input class="js-filter form-control" type="text" value="">
</th>
<th>
<input class="js-filter form-control" type="text" value="">
</th>
<th>
<input class="js-filter form-control" type="text" value="">
</th>
</tr>
</thead>
<tbody>
<tr class="boton_enlace_directo" data-destino="newmail" data-id="Redactar E-Mail" data-vars="var_fichero_gdrive=1kth1GhrmMEBK2cAMyiy_4Dw1qlJFNdXVuXajJ6nMTQgvar_fichero_gdriveManual KumbiaPHP 1.0 beta2var_fichero_gdriveapplication/vnd.google-apps.documentvar_fichero_gdrivevar_fichero_gdrive">
<td>application/vnd.google-apps.document</td>
<td></td>
<td>05/03/2015</td>
<td>Manual KumbiaPHP 1.0 beta2</td>
</tr>
<tr class="boton_enlace_directo" data-destino="newmail" data-id="Redactar E-Mail" data-vars="var_fichero_gdrive=1PwXa6f32BJuAC_m5X5wB9lPzoXAg__uKdUx-1efY4owvar_fichero_gdrive1392970712_Informe 2.docxvar_fichero_gdriveapplication/vnd.google-apps.documentvar_fichero_gdrivevar_fichero_gdrive">
<td>application/vnd.google-apps.document</td>
<td></td>
<td>15/09/2014</td>
<td>1392970712_Informe 2.docx</td>
</tr>
<tr class="boton_enlace_directo" data-destino="newmail" data-id="Redactar E-Mail" data-vars="var_fichero_gdrive=0B4X2ktyVTp3mVmtjR2JTSTVreE0var_fichero_gdrive148b14b859c2fa4a.htmlvar_fichero_gdrivetext/htmlvar_fichero_gdrivehttps://docs.google.com/uc?id=0B4X2ktyVTp3mVmtjR2JTSTVreE0&export=downloadvar_fichero_gdrive16">
<td>text/html</td>
<td></td>
<td>26/09/2014</td>
<td>148b14b859c2fa4a.html</td>
</tr>
</tbody>
</table>
在每个标签中,我添加一些数据属性以便接收它们
if( isset($_REQUEST['var_fichero_gdrive']) && $_REQUEST['var_fichero_gdrive']!="" ){
$metadata_fichero = explode("var_fichero_gdrive",$_REQUEST['var_fichero_gdrive']); //guardamos el array en una nueva variable
$fichero_gdrive = array(
"name" => $metadata_fichero[1],
"type" => $metadata_fichero[2],
"tmp_name" => $metadata_fichero[3],
"error" => 0,
"size" => $metadata_fichero[4]
);
$_FILES['file'] = $fichero_gdrive;
unset($fichero_gdrive,$metadata_fichero);
$gest->uploadAttachment();
}
请帮忙吗?
答案 0 :(得分:0)
我终于通过&#34; downloadUrl&#34;获得了它。 google驱动器api返回的param。有了它,我访问了谷歌驱动器文件内容,并且由于strin g $ _REQUEST [&#39; var_fichero_gdrive&#39;])(我在上面提到过),我可以获得donwloadUrl参数,即&#34 ; var_fichero_gdrive&#34;是这样的字符串:
var_fichero_gdrive=IDvar_fichero_gdriveNAMEvar_fichero_gdriveDOWNLOAD_URL
我用ajax调用php,在php中我拿起这个变量,我使用explode来获取这些google驱动器文件数据(你可以添加你想要的):
$metadata_fichero = explode("var_fichero_gdrive",$_REQUEST['var_fichero_gdrive'];
如果没有downloadUrl param,我会这样做:
if ( !isset($downloadUrl) || trim($downloadUrl) == "" ) {
$file["downloadUrl"] = $file->exportLinks['application/pdf'];
}
在上面的行中,我创建了一个新的downloadUrl,感谢exportLinks。
最后,我使用file_put_contents将文件下载的内容插入到tmp目录中的文件中:
$lDrive = new CGoogleDrive(TOKEN);
$response_body = $lDrive->getDownloadFile( ID_GOOGLE_DRIVE_FILE );
file_put_contents( $dest, $response_body );
希望它有所帮助。您需要根据自己的需要调整上述代码。 的问候,