自动附加google个驱动文件发送邮件
attach google drive file automatically to send mail
我在 php,我需要自动附加一个 google 驱动器文件,以便通过邮件发送。
我现在拥有的是:
HTML Table 像这样:
蒂波
<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>
在每个标签中,我添加了一些数据属性以获取它们
- 我很好地掌握了这些参数,并且很好地加载了新邮件表单的模板。但我不知道如何自动附加 google 驱动器文件。我正在尝试这个:
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();
}
有什么帮助吗?
最后通过google驱动apireturns的"downloadUrl"参数得到了。通过它我可以访问 google 驱动器文件内容,并且由于字符串 $_REQUEST['var_fichero_gdrive']) (我在上面提到过),我可以获得 donwloadUrl 参数,即 "var_fichero_gdrive" 是这样的字符串:
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 参数,我会这样做:
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 );
希望对您有所帮助。您需要根据需要调整上面的代码。
此致,
我在 php,我需要自动附加一个 google 驱动器文件,以便通过邮件发送。 我现在拥有的是:
HTML Table 像这样:
蒂波
<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>
在每个标签中,我添加了一些数据属性以获取它们
- 我很好地掌握了这些参数,并且很好地加载了新邮件表单的模板。但我不知道如何自动附加 google 驱动器文件。我正在尝试这个:
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();
}
有什么帮助吗?
最后通过google驱动apireturns的"downloadUrl"参数得到了。通过它我可以访问 google 驱动器文件内容,并且由于字符串 $_REQUEST['var_fichero_gdrive']) (我在上面提到过),我可以获得 donwloadUrl 参数,即 "var_fichero_gdrive" 是这样的字符串:
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 参数,我会这样做:
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 );
希望对您有所帮助。您需要根据需要调整上面的代码。 此致,