附加谷歌驱动器文件自动发送邮件



我在php,我需要附加一个谷歌驱动器文件自动,通过邮件发送它。我现在有:

  1. HTML表格如下:

    蒂波

            <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&amp;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();
    }
    
    请帮忙好吗?

    我最终通过google drive api返回的"downloadUrl"参数获得了它。有了它,我可以访问google drive文件内容,并且由于字符串g $_REQUEST['var_fichero_gdrive'])(我上面提到的),我可以获得downloadurl参数,也就是说,"var_fichero_gdrive"是这样的字符串:

    var_fichero_gdrive=IDvar_fichero_gdriveNAMEvar_fichero_gdriveDOWNLOAD_URL
    

    我调用php与ajax,并在php中我拿起这个变量,我使用爆炸,以获得这些谷歌驱动器文件数据(你可以添加你想要的):

    $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 );
    

    希望有帮助。您需要根据您的需要调整上面的代码。问候,

    相关内容

    • 没有找到相关文章

    最新更新