亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

上傳 Google 云端硬盤文件 - PNG、JPEG、PDF

上傳 Google 云端硬盤文件 - PNG、JPEG、PDF

PHP
慕碼人8056858 2023-08-26 10:12:05
我目前有一個功能可以成功地將 jpg 文件上傳到谷歌驅動器。我想知道如何修改該功能,以便我也可以將 pdf、jpg、png 和 docx 文件上傳到 Google Drive。這是我的代碼:function uploadFiles($filePath) {    $file = new Google_Service_Drive_DriveFile();    $file->setName(uniqid().'.jpg');    $file->setDescription('A test document');    $file->setMimeType('image/jpeg');    $data = file_get_contents($filePath);    $createdFile = $this->service->files->create($file, array(        'data' => $data,        'mimeType' => 'image/jpeg',        'uploadType' => 'multipart'    ));}任何幫助表示贊賞。謝謝。
查看完整描述

1 回答

?
慕妹3146593

TA貢獻1820條經驗 獲得超9個贊

pdf, jpg, png, and docx在文件上傳為 的情況下pdf, jpg, png, and docx,當使用 Drive API 中的 Files: create 方法上傳文件時,似乎會自動檢測文件的 mimeType。我認為對于你的情況,可以使用這種情況。因此,請按如下方式修改您的腳本。


修改后的腳本:

function uploadFiles($filePath) {

    $file = new Google_Service_Drive_DriveFile();

    $file->setName(uniqid());

    $file->setDescription('A test document');


    $data = file_get_contents($filePath);


    $createdFile = $this->service->files->create($file, array(

        'data' => $data,

        'uploadType' => 'multipart'

    ));

}

通過上述修改,對于pdf, jpg, png, and docx,上傳的文件具有正確的mimeType。


查看完整回答
反對 回復 2023-08-26
  • 1 回答
  • 0 關注
  • 172 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號